Compare commits
2 Commits
b7f5c65013
...
8dca0641f5
Author | SHA1 | Date |
---|---|---|
Michael Puckett | 8dca0641f5 | |
Michael Puckett | 139265023a |
|
@ -2065,6 +2065,102 @@
|
|||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui": {
|
||||
"version": "8.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
|
||||
"integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"string-width": "^5.1.2",
|
||||
"string-width-cjs": "npm:string-width@^4.2.0",
|
||||
"strip-ansi": "^7.0.1",
|
||||
"strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
|
||||
"wrap-ansi": "^8.1.0",
|
||||
"wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/ansi-regex": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz",
|
||||
"integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/ansi-styles": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz",
|
||||
"integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/emoji-regex": {
|
||||
"version": "9.2.2",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
|
||||
"integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/string-width": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
|
||||
"integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"eastasianwidth": "^0.2.0",
|
||||
"emoji-regex": "^9.2.2",
|
||||
"strip-ansi": "^7.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/strip-ansi": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz",
|
||||
"integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": "^6.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui/node_modules/wrap-ansi": {
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz",
|
||||
"integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-styles": "^6.1.0",
|
||||
"string-width": "^5.0.1",
|
||||
"strip-ansi": "^7.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/string-locale-compare": {
|
||||
"version": "1.1.0",
|
||||
"dev": true,
|
||||
|
@ -3523,6 +3619,16 @@
|
|||
"url": "https://opencollective.com/parcel"
|
||||
}
|
||||
},
|
||||
"node_modules/@pkgjs/parseargs": {
|
||||
"version": "0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
||||
"integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@protobufjs/aspromise": {
|
||||
"version": "1.1.2",
|
||||
"license": "BSD-3-Clause"
|
||||
|
@ -3669,6 +3775,12 @@
|
|||
"integrity": "sha512-ulw4d+vW1HKn4oErSmNN2HYEcHGq0N1C5exlrMM0CRqX1UUpFhGb5lwiom5j9KN3LBJJDLRmYIZz1ghm7FIzZw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/jasmine": {
|
||||
"version": "4.3.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.3.5.tgz",
|
||||
"integrity": "sha512-9YHUdvuNDDRJYXZwHqSsO72Ok0vmqoJbNn73ttyITQp/VA60SarnZ+MPLD37rJAhVoKp+9BWOvJP5tHIRfZylQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.11",
|
||||
"dev": true,
|
||||
|
@ -5409,6 +5521,12 @@
|
|||
"stream-shift": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/eastasianwidth": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
|
||||
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/ecdsa-sig-formatter": {
|
||||
"version": "1.0.11",
|
||||
"license": "Apache-2.0",
|
||||
|
@ -6299,6 +6417,34 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/foreground-child": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz",
|
||||
"integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"cross-spawn": "^7.0.0",
|
||||
"signal-exit": "^4.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/foreground-child/node_modules/signal-exit": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
|
||||
"integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.0",
|
||||
"license": "MIT",
|
||||
|
@ -7621,6 +7767,24 @@
|
|||
"whatwg-fetch": "^3.4.1"
|
||||
}
|
||||
},
|
||||
"node_modules/jackspeak": {
|
||||
"version": "2.2.2",
|
||||
"resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.2.2.tgz",
|
||||
"integrity": "sha512-mgNtVv4vUuaKA97yxUHoA3+FkuhtxkjdXEWOyB/N76fjy0FjezEt34oy3epBtvCvS+7DyKwqCFWx/oJLV5+kCg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@isaacs/cliui": "^8.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@pkgjs/parseargs": "^0.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/jake": {
|
||||
"version": "10.8.5",
|
||||
"dev": true,
|
||||
|
@ -9901,6 +10065,40 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/path-scurry": {
|
||||
"version": "1.10.1",
|
||||
"resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.1.tgz",
|
||||
"integrity": "sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"lru-cache": "^9.1.1 || ^10.0.0",
|
||||
"minipass": "^5.0.0 || ^6.0.2 || ^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/path-scurry/node_modules/lru-cache": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.0.tgz",
|
||||
"integrity": "sha512-svTf/fzsKHffP42sujkO/Rjs37BCIsQVRCeNYIm9WN8rgT7ffoUnRtZCqU+6BqcSBdv8gwJeTz8knJpgACeQMw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "14 || >=16.14"
|
||||
}
|
||||
},
|
||||
"node_modules/path-scurry/node_modules/minipass": {
|
||||
"version": "7.0.2",
|
||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.2.tgz",
|
||||
"integrity": "sha512-eL79dXrE1q9dBbDCLg7xfn/vl7MS4F1gvJAgjJrQli/jbQWdUttuVawphqpffoIYfRdq78LHx6GP4bU/EQ2ATA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "6.2.1",
|
||||
"license": "MIT"
|
||||
|
@ -11039,6 +11237,21 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/string-width-cjs": {
|
||||
"name": "string-width",
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"emoji-regex": "^8.0.0",
|
||||
"is-fullwidth-code-point": "^3.0.0",
|
||||
"strip-ansi": "^6.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi": {
|
||||
"version": "6.0.1",
|
||||
"license": "MIT",
|
||||
|
@ -11049,6 +11262,19 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi-cjs": {
|
||||
"name": "strip-ansi",
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-bom": {
|
||||
"version": "4.0.0",
|
||||
"dev": true,
|
||||
|
@ -11311,8 +11537,9 @@
|
|||
},
|
||||
"node_modules/ts-node": {
|
||||
"version": "10.9.1",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz",
|
||||
"integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cspotcode/source-map-support": "^0.8.0",
|
||||
"@tsconfig/node10": "^1.0.7",
|
||||
|
@ -11353,8 +11580,9 @@
|
|||
},
|
||||
"node_modules/tsconfig-paths": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz",
|
||||
"integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"json5": "^2.2.2",
|
||||
"minimist": "^1.2.6",
|
||||
|
@ -11759,6 +11987,24 @@
|
|||
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi-cjs": {
|
||||
"name": "wrap-ansi",
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
||||
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-styles": "^4.0.0",
|
||||
"string-width": "^4.1.0",
|
||||
"strip-ansi": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"license": "ISC"
|
||||
|
@ -12296,14 +12542,92 @@
|
|||
"jsonld": "^8.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jasmine": "^4.3.5",
|
||||
"@types/jsonld": "^1.5.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"jasmine": "^5.1.0",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
}
|
||||
},
|
||||
"packages/utilities/node_modules/brace-expansion": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"balanced-match": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"packages/utilities/node_modules/glob": {
|
||||
"version": "10.3.3",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-10.3.3.tgz",
|
||||
"integrity": "sha512-92vPiMb/iqpmEgsOoIDvTjc50wf9CCCvMzsi6W0JLPeUKE8TWP1a73PgqSrqy7iAZxaSD1YdzU7QZR5LF51MJw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"foreground-child": "^3.1.0",
|
||||
"jackspeak": "^2.0.3",
|
||||
"minimatch": "^9.0.1",
|
||||
"minipass": "^5.0.0 || ^6.0.2 || ^7.0.0",
|
||||
"path-scurry": "^1.10.1"
|
||||
},
|
||||
"bin": {
|
||||
"glob": "dist/cjs/src/bin.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"packages/utilities/node_modules/jasmine": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine/-/jasmine-5.1.0.tgz",
|
||||
"integrity": "sha512-prmJlC1dbLhti4nE4XAPDWmfJesYO15sjGXVp7Cs7Ym5I9Xtwa/hUHxxJXjnpfLO72+ySttA0Ztf8g/RiVnUKw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"glob": "^10.2.2",
|
||||
"jasmine-core": "~5.1.0"
|
||||
},
|
||||
"bin": {
|
||||
"jasmine": "bin/jasmine.js"
|
||||
}
|
||||
},
|
||||
"packages/utilities/node_modules/jasmine-core": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-5.1.0.tgz",
|
||||
"integrity": "sha512-bFMMwpKuTZXCuGd51yClFobw5SOtad1kmdWnYO8dNwYV8i01Xj0C2+nyQpSKl1EKxiPfyd1ZgBl/rsusL3aS6w==",
|
||||
"dev": true
|
||||
},
|
||||
"packages/utilities/node_modules/minimatch": {
|
||||
"version": "9.0.3",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz",
|
||||
"integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"packages/utilities/node_modules/minipass": {
|
||||
"version": "7.0.2",
|
||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.2.tgz",
|
||||
"integrity": "sha512-eL79dXrE1q9dBbDCLg7xfn/vl7MS4F1gvJAgjJrQli/jbQWdUttuVawphqpffoIYfRdq78LHx6GP4bU/EQ2ATA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=16 || 14 >=14.17"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,12 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
/**
|
||||
* Applies the default JSON-LD context to an {@link AP.Entity}.
|
||||
*
|
||||
* If the Entity already has a context, it will not be overwritten. This
|
||||
* function does not use JSON-LD compaction.
|
||||
*
|
||||
* @returns The {@link AP.Entity} with the default context applied.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#the-context
|
||||
*/
|
||||
export declare function applyContext(entity: AP.Entity): AP.Entity;
|
||||
|
|
|
@ -3,18 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.applyContext = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
const globals_1 = require("./globals");
|
||||
/**
|
||||
* Applies the default JSON-LD context to an {@link AP.Entity}.
|
||||
*
|
||||
* If the Entity already has a context, it will not be overwritten. This
|
||||
* function does not use JSON-LD compaction.
|
||||
*
|
||||
* @returns The {@link AP.Entity} with the default context applied.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#the-context
|
||||
*/
|
||||
function applyContext(entity) {
|
||||
if (!entity['@context']) {
|
||||
if (type_utilities_1.guard.isApActor(entity)) {
|
||||
entity['@context'] = [
|
||||
new URL(globals_1.ACTIVITYSTREAMS_CONTEXT),
|
||||
new URL(globals_1.W3ID_SECURITY_CONTEXT),
|
||||
{
|
||||
'schema:PropertyValue': new URL('https://schema.org/PropertyValue'),
|
||||
'schema:value': new URL('https://schema.org/value'),
|
||||
'schema:name': new URL('https://schema.org/name'),
|
||||
},
|
||||
];
|
||||
entity['@context'] = globals_1.DEFAULT_ACTOR_CONTEXT_AS_URLS;
|
||||
}
|
||||
else {
|
||||
entity['@context'] = new URL(globals_1.ACTIVITYSTREAMS_CONTEXT);
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"applyContext.js","sourceRoot":"","sources":["../src/applyContext.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AACrD,uCAA2E;AAE3E,SAAgB,YAAY,CAAC,MAAiB;IAC5C,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QACvB,IAAI,sBAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;YAC3B,MAAM,CAAC,UAAU,CAAC,GAAG;gBACnB,IAAI,GAAG,CAAC,iCAAuB,CAAC;gBAChC,IAAI,GAAG,CAAC,+BAAqB,CAAC;gBAC9B;oBACE,sBAAsB,EAAE,IAAI,GAAG,CAAC,kCAAkC,CAAC;oBACnE,cAAc,EAAE,IAAI,GAAG,CAAC,0BAA0B,CAAC;oBACnD,aAAa,EAAE,IAAI,GAAG,CAAC,yBAAyB,CAAC;iBAClD;aACF,CAAC;SACH;aAAM;YACL,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,iCAAuB,CAAC,CAAC;SACvD;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlBD,oCAkBC"}
|
||||
{"version":3,"file":"applyContext.js","sourceRoot":"","sources":["../src/applyContext.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AACrD,uCAGmB;AAEnB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAAC,MAAiB;IAC5C,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QACvB,IAAI,sBAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;YAC3B,MAAM,CAAC,UAAU,CAAC,GAAG,uCAA6B,CAAC;SACpD;aAAM;YACL,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,iCAAuB,CAAC,CAAC;SACvD;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAVD,oCAUC"}
|
|
@ -1,2 +1,21 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
/**
|
||||
* Removes the private `bto` and `bcc` properties from an {@link AP.Entity}
|
||||
* so they don't leak out upon delivery.
|
||||
*
|
||||
* If the Entity is a {@link AP.TransitiveActivity}, the `object` property will
|
||||
* also be cleaned.
|
||||
*
|
||||
* From the ActivityPub spec:
|
||||
*
|
||||
* > `bto` and `bcc` already must be removed for delivery, but servers are free
|
||||
* > to decide how to represent the object in their own storage systems.
|
||||
* > However, since bto and bcc are only intended to be known/seen by the
|
||||
* > original author of the object/activity, servers should omit these
|
||||
* > properties during display as well.
|
||||
*
|
||||
* @returns The Entity with the private properties removed.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#security-not-displaying-bto-bcc
|
||||
**/
|
||||
export declare function cleanProps(entity: AP.Entity): AP.Entity;
|
||||
|
|
|
@ -1,6 +1,26 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.cleanProps = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
/**
|
||||
* Removes the private `bto` and `bcc` properties from an {@link AP.Entity}
|
||||
* so they don't leak out upon delivery.
|
||||
*
|
||||
* If the Entity is a {@link AP.TransitiveActivity}, the `object` property will
|
||||
* also be cleaned.
|
||||
*
|
||||
* From the ActivityPub spec:
|
||||
*
|
||||
* > `bto` and `bcc` already must be removed for delivery, but servers are free
|
||||
* > to decide how to represent the object in their own storage systems.
|
||||
* > However, since bto and bcc are only intended to be known/seen by the
|
||||
* > original author of the object/activity, servers should omit these
|
||||
* > properties during display as well.
|
||||
*
|
||||
* @returns The Entity with the private properties removed.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#security-not-displaying-bto-bcc
|
||||
**/
|
||||
function cleanProps(entity) {
|
||||
const cleanedEntity = { ...entity };
|
||||
if ('bto' in cleanedEntity) {
|
||||
|
@ -9,6 +29,10 @@ function cleanProps(entity) {
|
|||
if ('bcc' in cleanedEntity) {
|
||||
delete cleanedEntity.bcc;
|
||||
}
|
||||
if (type_utilities_1.guard.isApTransitiveActivity(cleanedEntity) &&
|
||||
type_utilities_1.guard.isApEntity(cleanedEntity.object)) {
|
||||
cleanedEntity.object = cleanProps(cleanedEntity.object);
|
||||
}
|
||||
return cleanedEntity;
|
||||
}
|
||||
exports.cleanProps = cleanProps;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"cleanProps.js","sourceRoot":"","sources":["../src/cleanProps.ts"],"names":[],"mappings":";;;AAMA,SAAgB,UAAU,CAAC,MAAiB;IAC1C,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAEpC,IAAI,KAAK,IAAI,aAAa,EAAE;QAC1B,OAAO,aAAa,CAAC,GAAG,CAAC;KAC1B;IAED,IAAI,KAAK,IAAI,aAAa,EAAE;QAC1B,OAAO,aAAa,CAAC,GAAG,CAAC;KAC1B;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAZD,gCAYC"}
|
||||
{"version":3,"file":"cleanProps.js","sourceRoot":"","sources":["../src/cleanProps.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AAErD;;;;;;;;;;;;;;;;;;IAkBI;AACJ,SAAgB,UAAU,CAAC,MAAiB;IAC1C,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAEpC,IAAI,KAAK,IAAI,aAAa,EAAE;QAC1B,OAAO,aAAa,CAAC,GAAG,CAAC;KAC1B;IAED,IAAI,KAAK,IAAI,aAAa,EAAE;QAC1B,OAAO,aAAa,CAAC,GAAG,CAAC;KAC1B;IAED,IACE,sBAAK,CAAC,sBAAsB,CAAC,aAAa,CAAC;QAC3C,sBAAK,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,EACtC;QACA,aAAa,CAAC,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;KACzD;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAnBD,gCAmBC"}
|
|
@ -1,2 +1,15 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
/**
|
||||
* Compresses an Entity by replacing all nested Entities with their URLs.
|
||||
*
|
||||
* This is useful for storing Entities in a database, as it removes the need to
|
||||
* store the entire Entity, or for sending Entities over the network, as it
|
||||
* reduces the size of the payload.
|
||||
*
|
||||
* @note This follows rules similar to JSON-LD compaction, but it does not
|
||||
* follow the JSON-LD spec exactly. For example, it does not use the `@context`
|
||||
* property to determine the full URL of a property.
|
||||
*
|
||||
* @returns The compressed Entity, or null if not an Entity.
|
||||
*/
|
||||
export declare function compressEntity(entity: AP.Entity): AP.Entity | null;
|
||||
|
|
|
@ -2,11 +2,29 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.compressEntity = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
/**
|
||||
* Compresses an Entity by replacing all nested Entities with their URLs.
|
||||
*
|
||||
* This is useful for storing Entities in a database, as it removes the need to
|
||||
* store the entire Entity, or for sending Entities over the network, as it
|
||||
* reduces the size of the payload.
|
||||
*
|
||||
* @note This follows rules similar to JSON-LD compaction, but it does not
|
||||
* follow the JSON-LD spec exactly. For example, it does not use the `@context`
|
||||
* property to determine the full URL of a property.
|
||||
*
|
||||
* @returns The compressed Entity, or null if not an Entity.
|
||||
*/
|
||||
function compressEntity(entity) {
|
||||
var _a;
|
||||
return (_a = type_utilities_1.cast.isApEntity(compressObject(entity))) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
exports.compressEntity = compressEntity;
|
||||
/**
|
||||
* Compresses an object by replacing all nested Entities with their URLs.
|
||||
*
|
||||
* @returns The compressed object.
|
||||
*/
|
||||
function compressObject(object) {
|
||||
const compressed = {};
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
|
@ -14,6 +32,12 @@ function compressObject(object) {
|
|||
}
|
||||
return compressed;
|
||||
}
|
||||
/**
|
||||
* Compresses an unknown value by replacing all nested Entities with their
|
||||
* URLs.
|
||||
*
|
||||
* @returns The compressed value.
|
||||
*/
|
||||
function compressUnknown(item) {
|
||||
if (!type_utilities_1.guard.exists(item)) {
|
||||
return item;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"compressEntity.js","sourceRoot":"","sources":["../src/compressEntity.ts"],"names":[],"mappings":";;;AACA,iEAA2D;AAE3D,SAAgB,cAAc,CAAC,MAAiB;;IAC9C,OAAO,MAAA,qBAAI,CAAC,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,mCAAI,IAAI,CAAC;AACzD,CAAC;AAFD,wCAEC;AAED,SAAS,cAAc,CACrB,MAA+B;IAE/B,MAAM,UAAU,GAA4B,EAAE,CAAC;IAE/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,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UAAU,GAA4B,EAAE,CAAC;IAE/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,UAAU,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;KAC1C;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,IAAa;IACpC,IAAI,CAAC,sBAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,sBAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;KAClC;IAED,MAAM,MAAM,GAAG,qBAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAErC,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAI,IAAI,MAAM,IAAI,sBAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QAC5C,OAAO,MAAM,CAAC,EAAE,CAAC;KAClB;IAED,IAAI,KAAK,IAAI,MAAM,IAAI,sBAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;QAC9C,OAAO,MAAM,CAAC,GAAG,CAAC;KACnB;IAED,IAAI,MAAM,IAAI,MAAM,IAAI,sBAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QAChD,OAAO,MAAM,CAAC,IAAI,CAAC;KACpB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@ -1,2 +1,13 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
/**
|
||||
* Converts an Entity to a plain JSON object.
|
||||
*
|
||||
* This is needed to store the Entity in a database or send it over the network,
|
||||
* as the Entity may contain URLs, Dates, and other non-JSON values.
|
||||
*
|
||||
* @returns The plain object.
|
||||
*
|
||||
* @todo The fallthrough case for objects relies on the `toString()` method.
|
||||
* This is not ideal, as it may not always produce the desired result.
|
||||
*/
|
||||
export declare function convertEntityToJson(object: AP.Entity): Record<string, unknown>;
|
||||
|
|
|
@ -2,11 +2,27 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.convertEntityToJson = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
/**
|
||||
* Converts an Entity to a plain JSON object.
|
||||
*
|
||||
* This is needed to store the Entity in a database or send it over the network,
|
||||
* as the Entity may contain URLs, Dates, and other non-JSON values.
|
||||
*
|
||||
* @returns The plain object.
|
||||
*
|
||||
* @todo The fallthrough case for objects relies on the `toString()` method.
|
||||
* This is not ideal, as it may not always produce the desired result.
|
||||
*/
|
||||
function convertEntityToJson(object) {
|
||||
var _a;
|
||||
return (_a = type_utilities_1.cast.isPlainObject(convertObject(object))) !== null && _a !== void 0 ? _a : {};
|
||||
}
|
||||
exports.convertEntityToJson = convertEntityToJson;
|
||||
/**
|
||||
* Converts an object to a plain JSON object.
|
||||
*
|
||||
* @returns The plain object.
|
||||
*/
|
||||
function convertObject(object) {
|
||||
const converted = {};
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
|
@ -14,6 +30,11 @@ function convertObject(object) {
|
|||
}
|
||||
return converted;
|
||||
}
|
||||
/**
|
||||
* Converts an unknown value to a plain JSON value.
|
||||
*
|
||||
* @returns The plain value.
|
||||
*/
|
||||
function convertUnknown(value) {
|
||||
if (!type_utilities_1.guard.exists(value)) {
|
||||
return value;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"convertEntityToJson.js","sourceRoot":"","sources":["../src/convertEntityToJson.ts"],"names":[],"mappings":";;;AACA,iEAA2D;AAE3D,SAAgB,mBAAmB,CACjC,MAAiB;;IAEjB,OAAO,MAAA,qBAAI,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,mCAAI,EAAE,CAAC;AACz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;IAE9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;KACxC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,CAAC,sBAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IAED,IAAI,sBAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;KAClC;IAED,IAAI,sBAAK,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;QAC9B,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;KAC7B;IAED,IAAI,sBAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC5B;IAED,IAAI,sBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACzB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@ -1,3 +1,22 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import * as jsonld from 'jsonld';
|
||||
export declare const convertJsonLdToEntity: (document: jsonld.JsonLdDocument) => Promise<AP.Entity | null>;
|
||||
/**
|
||||
* Converts a JSON-LD object to a compacted ActivityPub Entity.
|
||||
*
|
||||
* First, the JSON-LD object is compacted using the `jsonld` library. It uses
|
||||
* the ActivityPub context as the base context and adds the following contexts
|
||||
* to it:
|
||||
*
|
||||
* - https://w3id.org/security/v1 for encryption/signatures
|
||||
* - https://schema.org for Mastodon's profile metadata
|
||||
*
|
||||
* Then, the compacted object is converted to an ActivityPub Entity.
|
||||
*
|
||||
* @todo An updated context
|
||||
* will be applied to the Entity, unless it already has one.
|
||||
*
|
||||
* @returns The ActivityPub Entity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#compacted-document-form
|
||||
*/
|
||||
export declare function convertJsonLdToEntity(document: jsonld.JsonLdDocument): Promise<AP.Entity | null>;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,7 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
/**
|
||||
* Converts a JSON object to an Entity with deserialized values.
|
||||
*
|
||||
* @returns The Entity, or null if not an Entity.
|
||||
*/
|
||||
export declare function convertJsonToEntity(object: Record<string, unknown>): AP.Entity | null;
|
||||
|
|
|
@ -3,11 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.convertJsonToEntity = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
const globals_1 = require("./globals");
|
||||
/**
|
||||
* Converts a JSON object to an Entity with deserialized values.
|
||||
*
|
||||
* @returns The Entity, or null if not an Entity.
|
||||
*/
|
||||
function convertJsonToEntity(object) {
|
||||
var _a;
|
||||
return (_a = type_utilities_1.cast.isApEntity(convertObject(object))) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
exports.convertJsonToEntity = convertJsonToEntity;
|
||||
/**
|
||||
* Deserializes serialized values in an object into their proper types.
|
||||
*
|
||||
* @returns The object with deserialized values.
|
||||
*/
|
||||
function convertObject(object) {
|
||||
const converted = {};
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
|
@ -15,6 +25,11 @@ function convertObject(object) {
|
|||
}
|
||||
return converted;
|
||||
}
|
||||
/**
|
||||
* Deserializes an unknown value into a known type.
|
||||
*
|
||||
* @returns The deserialized value.
|
||||
*/
|
||||
function convertUnknown(value) {
|
||||
if (!type_utilities_1.guard.exists(value)) {
|
||||
return value;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"convertJsonToEntity.js","sourceRoot":"","sources":["../src/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AAY,CAAC,CAAC;SAC9B;QAED,IAAI;YACF,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;gBAC5B,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;aACvB;iBAAM;gBACL,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAE/B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;oBACvB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;iBACvB;gBAED,OAAO,KAAK,CAAC;aACd;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@ -1,2 +1,7 @@
|
|||
/// <reference types="node" />
|
||||
/**
|
||||
* Removes duplicate URLs from an array of URLs.
|
||||
*
|
||||
* @returns An array of unique URLs.
|
||||
*/
|
||||
export declare const deduplicateUrls: (unfilteredUrls: URL[]) => import("url").URL[];
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deduplicateUrls = void 0;
|
||||
/**
|
||||
* Removes duplicate URLs from an array of URLs.
|
||||
*
|
||||
* @returns An array of unique URLs.
|
||||
*/
|
||||
const deduplicateUrls = (unfilteredUrls) => {
|
||||
return [...new Set(unfilteredUrls.map((url) => url.toString()))].map((url) => new URL(url));
|
||||
};
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"deduplicateUrls.js","sourceRoot":"","sources":["../src/deduplicateUrls.ts"],"names":[],"mappings":";;;AAAO,MAAM,eAAe,GAAG,CAAC,cAAqB,EAAE,EAAE;IACvD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAClE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CACtB,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B"}
|
||||
{"version":3,"file":"deduplicateUrls.js","sourceRoot":"","sources":["../src/deduplicateUrls.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAAC,cAAqB,EAAE,EAAE;IACvD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAClE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CACtB,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B"}
|
|
@ -1,2 +1,12 @@
|
|||
/// <reference types="node" />
|
||||
/**
|
||||
* Gets the database collection name for a given URL.
|
||||
*
|
||||
* Currently, all entities are stored in one of two collections:
|
||||
*
|
||||
* - `entity` for local entities
|
||||
* - `foreignEntity` for foreign/remote entities
|
||||
*
|
||||
* @returns The collection name.
|
||||
*/
|
||||
export declare const getCollectionNameByUrl: (url: URL) => "entity" | "foreignEntity";
|
||||
|
|
|
@ -2,6 +2,16 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getCollectionNameByUrl = void 0;
|
||||
const globals_1 = require("./globals");
|
||||
/**
|
||||
* Gets the database collection name for a given URL.
|
||||
*
|
||||
* Currently, all entities are stored in one of two collections:
|
||||
*
|
||||
* - `entity` for local entities
|
||||
* - `foreignEntity` for foreign/remote entities
|
||||
*
|
||||
* @returns The collection name.
|
||||
*/
|
||||
const getCollectionNameByUrl = (url) => {
|
||||
const isLocal = url.hostname === globals_1.LOCAL_HOSTNAME;
|
||||
if (!isLocal) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getCollectionNameByUrl.js","sourceRoot":"","sources":["../src/getCollectionNameByUrl.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAEpC,MAAM,sBAAsB,GAAG,CAAC,GAAQ,EAAE,EAAE;IACjD,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,wBAAc,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,eAAe,CAAC;KACxB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC"}
|
||||
{"version":3,"file":"getCollectionNameByUrl.js","sourceRoot":"","sources":["../src/getCollectionNameByUrl.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAE3C;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,CAAC,GAAQ,EAAE,EAAE;IACjD,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,wBAAc,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,eAAe,CAAC;KACxB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC"}
|
|
@ -1,2 +1,7 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
/**
|
||||
* Get the Entity from an EntityReference, if the EntityReference is an Entity.
|
||||
*
|
||||
* @returns The Entity, or null if not an Entity.
|
||||
*/
|
||||
export declare const getEntity: <T extends AP.Entity>(entity: undefined | null | AP.EntityReference | AP.EntityReference[]) => T | null;
|
||||
|
|
|
@ -26,6 +26,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.getEntity = void 0;
|
||||
const AP = __importStar(require("@activity-kit/types"));
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
/**
|
||||
* Get the Entity from an EntityReference, if the EntityReference is an Entity.
|
||||
*
|
||||
* @returns The Entity, or null if not an Entity.
|
||||
*/
|
||||
const getEntity = (entity) => {
|
||||
var _a, _b;
|
||||
if (!type_utilities_1.guard.exists(entity)) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getEntity.js","sourceRoot":"","sources":["../src/getEntity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,iEAA2D;AAEpD,MAAM,SAAS,GAAG,CACvB,MAAoE,EAC1D,EAAE;;IACZ,IAAI,CAAC,sBAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,sBAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,sBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;YAEtB,OAAO,MAAA,qBAAI,CAAC,UAAU,CAAgB,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,mCAAI,IAAI,CAAC;SAClE;QAED,OAAO,IAAI,CAAC;KACb;IAED,OAAO,MAAA,qBAAI,CAAC,UAAU,CAAgB,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,mCAAI,IAAI,CAAC;AACrE,CAAC,CAAC;AAtBW,QAAA,SAAS,aAsBpB"}
|
||||
{"version":3,"file":"getEntity.js","sourceRoot":"","sources":["../src/getEntity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,iEAA2D;AAE3D;;;;GAIG;AACI,MAAM,SAAS,GAAG,CACvB,MAAoE,EAC1D,EAAE;;IACZ,IAAI,CAAC,sBAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,sBAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,sBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;YAEtB,OAAO,MAAA,qBAAI,CAAC,UAAU,CAAgB,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,mCAAI,IAAI,CAAC;SAClE;QAED,OAAO,IAAI,CAAC;KACb;IAED,OAAO,MAAA,qBAAI,CAAC,UAAU,CAAgB,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,mCAAI,IAAI,CAAC;AACrE,CAAC,CAAC;AAtBW,QAAA,SAAS,aAsBpB"}
|
|
@ -1,3 +1,8 @@
|
|||
/// <reference types="node" />
|
||||
import * as AP from '@activity-kit/types';
|
||||
export declare const getId: (entity?: undefined | null | AP.EntityReference | AP.EntityReference[]) => URL | null;
|
||||
/**
|
||||
* Get the URL from an EntityReference.
|
||||
*
|
||||
* @returns The URL, or null if not a URL.
|
||||
*/
|
||||
export declare const getId: (entity: undefined | null | AP.EntityReference | AP.EntityReference[]) => URL | null;
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getId = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
/**
|
||||
* Get the URL from an EntityReference.
|
||||
*
|
||||
* @returns The URL, or null if not a URL.
|
||||
*/
|
||||
const getId = (entity) => {
|
||||
if (!type_utilities_1.guard.exists(entity)) {
|
||||
return null;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getId.js","sourceRoot":"","sources":["../src/getId.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AAE9C,MAAM,KAAK,GAAG,CACnB,MAAqE,EACzD,EAAE;IACd,IAAI,CAAC,sBAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,sBAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;QACv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BAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YAChD,OAAO,MAAM,CAAC,IAAI,CAAC;SACpB;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA1BW,QAAA,KAAK,SA0BhB"}
|
|
@ -1,28 +1,197 @@
|
|||
/// <reference types="node" />
|
||||
import * as jsonld from 'jsonld';
|
||||
/**
|
||||
* The port the server will listen on.
|
||||
*
|
||||
* Configurable via the `AP_PORT` environment variable.
|
||||
*
|
||||
* @default 3000
|
||||
*/
|
||||
export declare const PORT: number;
|
||||
/**
|
||||
* The server's hostname.
|
||||
*
|
||||
* Configurable via the `AP_HOST_NAME` environment variable.
|
||||
*
|
||||
* @default localhost
|
||||
*/
|
||||
export declare const LOCAL_HOSTNAME: string;
|
||||
/**
|
||||
* The protocol the server runs on.
|
||||
*
|
||||
* Configurable via the `AP_PROTOCOL` environment variable.
|
||||
*
|
||||
* @default http:
|
||||
*/
|
||||
export declare const PROTOCOL: string;
|
||||
/**
|
||||
* The database name.
|
||||
*
|
||||
* Configurable via the `AP_DB_NAME` environment variable.
|
||||
*
|
||||
* @default activitypub
|
||||
*/
|
||||
export declare const DB_NAME: string;
|
||||
/**
|
||||
* The server's domain including protocol and port.
|
||||
*
|
||||
* @example http://localhost:3000
|
||||
* @example https://example.com
|
||||
*/
|
||||
export declare const LOCAL_DOMAIN: string;
|
||||
/**
|
||||
* The JSON-LD context property key.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#the-context
|
||||
*/
|
||||
export declare const CONTEXT_KEY = "@context";
|
||||
/**
|
||||
* The JSON-LD context for ActivityPub.
|
||||
*/
|
||||
export declare const ACTIVITYSTREAMS_CONTEXT = "https://www.w3.org/ns/activitystreams";
|
||||
/**
|
||||
* The JSON-LD context for the W3ID security vocabulary.
|
||||
*
|
||||
* Used for signing and verifying signatures.
|
||||
*
|
||||
* @see https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.html
|
||||
*/
|
||||
export declare const W3ID_SECURITY_CONTEXT = "https://w3id.org/security/v1";
|
||||
/**
|
||||
* The JSON-LD context for the Schema.org vocabulary.
|
||||
*
|
||||
* @see https://schema.org/
|
||||
*/
|
||||
export declare const SCHEMA_ORG_CONTEXT = "https://schema.org/";
|
||||
/**
|
||||
* The JSON-LD context for the Linked Data Platform vocabulary.
|
||||
*
|
||||
* Some keys are used by ActivityPub, such as `ldp:inbox`.
|
||||
*
|
||||
* @see https://www.w3.org/TR/ldp/
|
||||
*/
|
||||
export declare const LDP_CONTEXT = "http://www.w3.org/ns/ldp#";
|
||||
/**
|
||||
* The JSON-LD context for the Relationship vocabulary.
|
||||
*
|
||||
* Used to provide additional information about a Relationship, however this
|
||||
* is not used by default.
|
||||
*
|
||||
* @see https://www.w3.org/TR/vocab-relationship/
|
||||
*/
|
||||
export declare const RELATIONSHIP_CONTEXT = "http://purl.org/vocab/relationship/";
|
||||
/**
|
||||
* The JSON-LD context for the Changeset vocabulary.
|
||||
*
|
||||
* Used to provide edit history for an Entity, such as a Note, however this
|
||||
* is not used by default.
|
||||
*
|
||||
* @see https://www.w3.org/TR/2013/REC-vocab-dqv-20130430/
|
||||
*/
|
||||
export declare const CHANGESET_CONTEXT = "http://purl.org/vocab/changeset/schema#";
|
||||
/**
|
||||
* The special Actor used to indicate that an Activity is public.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#public-addressing
|
||||
*/
|
||||
export declare const PUBLIC_ACTOR: string;
|
||||
export declare const LINKED_DATA_CONTENT_TYPE = "application/ld+json";
|
||||
/**
|
||||
* The username of the Actor representing the server.
|
||||
*
|
||||
* This is used primarily for fetching Entities on behalf of the server.
|
||||
*/
|
||||
export declare const SERVER_ACTOR_USERNAME = "bot";
|
||||
/**
|
||||
* The URL of the server's Shared Inbox.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#shared-inbox
|
||||
*/
|
||||
export declare const SHARED_INBOX_ID: string;
|
||||
/**
|
||||
* The HTTP Header key representing which content type is accepted by
|
||||
* the client, such as `application/activity+json`.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept
|
||||
*/
|
||||
export declare const ACCEPT_HEADER = "Accept";
|
||||
/**
|
||||
* The HTTP Header key representing which content type is being sent by
|
||||
* the server, such as `application/activity+json`.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
|
||||
*/
|
||||
export declare const CONTENT_TYPE_HEADER = "Content-Type";
|
||||
/**
|
||||
* The HTTP Header value representing the ActivityPub content type.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#retrieving-objects
|
||||
*/
|
||||
export declare const LINKED_DATA_CONTENT_TYPE = "application/ld+json";
|
||||
/**
|
||||
* The HTTP Header value representing the ActivityPub content type with
|
||||
* the ActivityStreams context.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#retrieving-objects
|
||||
*/
|
||||
export declare const ACTIVITYSTREAMS_CONTENT_TYPE_WITH_PROFILE: string;
|
||||
/**
|
||||
* The HTTP Header value representing the ActivityPub content type.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#retrieving-objects
|
||||
*/
|
||||
export declare const ACTIVITYSTREAMS_CONTENT_TYPE = "application/activity+json";
|
||||
/**
|
||||
* The HTTP Header value representing the XRD content type.
|
||||
*
|
||||
* This is used for WebFinger.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc6415
|
||||
*/
|
||||
export declare const XRD_CONTENT_TYPE = "application/xrd+xml";
|
||||
/**
|
||||
* The HTTP Header value representing the JRD content type.
|
||||
*
|
||||
* This is used for WebFinger.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc7033
|
||||
*/
|
||||
export declare const JRD_CONTENT_TYPE = "application/jrd+json";
|
||||
/**
|
||||
* The HTTP Header value representing the JSON content type.
|
||||
*
|
||||
* This is often the default content type for HTTP requests.
|
||||
*/
|
||||
export declare const JSON_CONTENT_TYPE = "application/json";
|
||||
/**
|
||||
* The HTTP Header value representing the HTML content type.
|
||||
*/
|
||||
export declare const HTML_CONTENT_TYPE = "text/html";
|
||||
/**
|
||||
* Regular Expression for a valid username.
|
||||
*/
|
||||
export declare const USERNAME_REGEXP: RegExp;
|
||||
/**
|
||||
* The default JSON-LD context for ActivityPub Actors.
|
||||
*
|
||||
* @see {@link ACTIVITYSTREAMS_CONTEXT}
|
||||
* @see {@link W3ID_SECURITY_CONTEXT}
|
||||
* @see {@link SCHEMA_ORG_CONTEXT}
|
||||
*/
|
||||
export declare const DEFAULT_ACTOR_CONTEXT: {
|
||||
'@vocab': string;
|
||||
sec: string;
|
||||
schema: string;
|
||||
};
|
||||
/**
|
||||
* The default JSON-LD context for ActivityPub Actors, with instances of URL in
|
||||
* place of strings.
|
||||
*/
|
||||
export declare const DEFAULT_ACTOR_CONTEXT_AS_URLS: {
|
||||
[k: string]: import("url").URL;
|
||||
};
|
||||
/**
|
||||
* Express-style route parameters.
|
||||
*/
|
||||
export declare const DEFAULT_ROUTES: {
|
||||
serverActor: string;
|
||||
serverInbox: string;
|
||||
|
@ -86,4 +255,16 @@ export declare const DEFAULT_ROUTES: {
|
|||
shares: string;
|
||||
replies: string;
|
||||
};
|
||||
/**
|
||||
* Reserved usernames, which may not be used by Actors because they may
|
||||
* conflict with routes.
|
||||
*/
|
||||
export declare const RESERVED_USERNAMES: string[];
|
||||
/**
|
||||
* Complete JSON-LD context definitions.
|
||||
*
|
||||
* Used for compacting JSON-LD objects.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#jsonld-context
|
||||
*/
|
||||
export declare const CONTEXT_DEFINITIONS: Record<string, jsonld.ContextDefinition>;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,7 @@
|
|||
/// <reference types="node" />
|
||||
/**
|
||||
* Determines whether a URL is local or not.
|
||||
*
|
||||
* @returns True if local, false if foreign.
|
||||
*/
|
||||
export declare function isLocal(url: URL): boolean;
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isLocal = void 0;
|
||||
const getCollectionNameByUrl_1 = require("./getCollectionNameByUrl");
|
||||
/**
|
||||
* Determines whether a URL is local or not.
|
||||
*
|
||||
* @returns True if local, false if foreign.
|
||||
*/
|
||||
function isLocal(url) {
|
||||
return (0, getCollectionNameByUrl_1.getCollectionNameByUrl)(url) !== 'foreignEntity';
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"isLocal.js","sourceRoot":"","sources":["../src/isLocal.ts"],"names":[],"mappings":";;;AAAA,qEAAkE;AAElE,SAAgB,OAAO,CAAC,GAAQ;IAC9B,OAAO,IAAA,+CAAsB,EAAC,GAAG,CAAC,KAAK,eAAe,CAAC;AACzD,CAAC;AAFD,0BAEC"}
|
||||
{"version":3,"file":"isLocal.js","sourceRoot":"","sources":["../src/isLocal.ts"],"names":[],"mappings":";;;AAAA,qEAAkE;AAElE;;;;GAIG;AACH,SAAgB,OAAO,CAAC,GAAQ;IAC9B,OAAO,IAAA,+CAAsB,EAAC,GAAG,CAAC,KAAK,eAAe,CAAC;AACzD,CAAC;AAFD,0BAEC"}
|
|
@ -1,4 +1,11 @@
|
|||
/// <reference types="node" />
|
||||
import type { IncomingMessage } from 'http';
|
||||
import * as AP from '@activity-kit/types';
|
||||
/**
|
||||
* Parse an HTTP stream into an Entity.
|
||||
*
|
||||
* @returns The Entity, or null if not found.
|
||||
*
|
||||
* @todo This is being depricated in favor of having adapters handle this.
|
||||
*/
|
||||
export declare function parseStream(req: IncomingMessage): Promise<AP.Entity | null>;
|
||||
|
|
|
@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.parseStream = void 0;
|
||||
const convertJsonLdToEntity_1 = require("./convertJsonLdToEntity");
|
||||
const streamToString_1 = require("./streamToString");
|
||||
/**
|
||||
* Parse an HTTP stream into an Entity.
|
||||
*
|
||||
* @returns The Entity, or null if not found.
|
||||
*
|
||||
* @todo This is being depricated in favor of having adapters handle this.
|
||||
*/
|
||||
async function parseStream(req) {
|
||||
return await (0, convertJsonLdToEntity_1.convertJsonLdToEntity)(JSON.parse(await (0, streamToString_1.streamToString)(req)));
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"parseStream.js","sourceRoot":"","sources":["../src/parseStream.ts"],"names":[],"mappings":";;;AAEA,mEAAgE;AAChE,qDAAkD;AAE3C,KAAK,UAAU,WAAW,CAC/B,GAAoB;IAEpB,OAAO,MAAM,IAAA,6CAAqB,EAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAA,+BAAc,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC;AAJD,kCAIC"}
|
||||
{"version":3,"file":"parseStream.js","sourceRoot":"","sources":["../src/parseStream.ts"],"names":[],"mappings":";;;AAEA,mEAAgE;AAChE,qDAAkD;AAElD;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,GAAoB;IAEpB,OAAO,MAAM,IAAA,6CAAqB,EAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAA,+BAAc,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC;AAJD,kCAIC"}
|
|
@ -1,3 +1,10 @@
|
|||
/// <reference types="node" />
|
||||
import { IncomingMessage } from 'http';
|
||||
/**
|
||||
* Converts an HTTP stream to a string.
|
||||
*
|
||||
* @returns The string.
|
||||
*
|
||||
* @todo This is being depricated in favor of having adapters handle this.
|
||||
*/
|
||||
export declare function streamToString(stream: IncomingMessage): Promise<string>;
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.streamToString = void 0;
|
||||
/**
|
||||
* Converts an HTTP stream to a string.
|
||||
*
|
||||
* @returns The string.
|
||||
*
|
||||
* @todo This is being depricated in favor of having adapters handle this.
|
||||
*/
|
||||
async function streamToString(stream) {
|
||||
if (stream) {
|
||||
const chunks = [];
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"streamToString.js","sourceRoot":"","sources":["../src/streamToString.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,cAAc,CAAC,MAAuB;IAC1D,IAAI,MAAM,EAAE;QACV,MAAM,MAAM,GAAG,EAAE,CAAC;QAElB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;YAChC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;SACjC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KAChD;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAZD,wCAYC"}
|
||||
{"version":3,"file":"streamToString.js","sourceRoot":"","sources":["../src/streamToString.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAAC,MAAuB;IAC1D,IAAI,MAAM,EAAE;QACV,MAAM,MAAM,GAAG,EAAE,CAAC;QAElB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;YAChC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;SACjC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KAChD;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAZD,wCAYC"}
|
|
@ -16,7 +16,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"build": "node .build.js",
|
||||
"build:bundle": "tsc-bundle tsconfig.json --outFile dist/bundle.js"
|
||||
"build:bundle": "tsc-bundle tsconfig.json --outFile dist/bundle.js",
|
||||
"test": "ts-node --project tsconfig.json node_modules/jasmine/bin/jasmine.js ./tests/**/*.test.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@activity-kit/type-utilities": "^0.4.56",
|
||||
|
@ -24,11 +25,15 @@
|
|||
"jsonld": "^8.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jasmine": "^4.3.5",
|
||||
"@types/jsonld": "^1.5.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"jasmine": "^5.1.0",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
},
|
||||
|
|
|
@ -1,20 +1,27 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import { DEFAULT_CONTEXT_AS_URLS } from './globals';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import {
|
||||
ACTIVITYSTREAMS_CONTEXT,
|
||||
DEFAULT_ACTOR_CONTEXT_AS_URLS,
|
||||
} from './globals';
|
||||
|
||||
/**
|
||||
* Applies the ActivityStreams context to an Entity. If the Entity already has a
|
||||
* JSON-LD context, it will not be overwritten.
|
||||
* Applies the default JSON-LD context to an {@link AP.Entity}.
|
||||
*
|
||||
* This is useful when creating an Entity from scratch, as it ensures that the
|
||||
* Entity has the proper context.
|
||||
* If the Entity already has a context, it will not be overwritten. This
|
||||
* function does not use JSON-LD compaction.
|
||||
*
|
||||
* @returns The Entity with the context applied.
|
||||
* @returns The {@link AP.Entity} with the default context applied.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#the-context
|
||||
*/
|
||||
export function applyContext(entity: AP.Entity): AP.Entity {
|
||||
if (!entity['@context']) {
|
||||
entity['@context'] = DEFAULT_CONTEXT_AS_URLS;
|
||||
if (guard.isApActor(entity)) {
|
||||
entity['@context'] = DEFAULT_ACTOR_CONTEXT_AS_URLS;
|
||||
} else {
|
||||
entity['@context'] = new URL(ACTIVITYSTREAMS_CONTEXT);
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
|
||||
/**
|
||||
* Removes the private `bto` and `bcc` properties from Entities so they don't
|
||||
* leak out upon delivery.
|
||||
* Removes the private `bto` and `bcc` properties from an {@link AP.Entity}
|
||||
* so they don't leak out upon delivery.
|
||||
*
|
||||
* If the Entity is a {@link AP.TransitiveActivity}, the `object` property will
|
||||
* also be cleaned.
|
||||
*
|
||||
* From the ActivityPub spec:
|
||||
*
|
||||
|
@ -27,5 +31,12 @@ export function cleanProps(entity: AP.Entity): AP.Entity {
|
|||
delete cleanedEntity.bcc;
|
||||
}
|
||||
|
||||
if (
|
||||
guard.isApTransitiveActivity(cleanedEntity) &&
|
||||
guard.isApEntity(cleanedEntity.object)
|
||||
) {
|
||||
cleanedEntity.object = cleanProps(cleanedEntity.object);
|
||||
}
|
||||
|
||||
return cleanedEntity;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path="../types/jsonldDocumentLoader.d.ts" />
|
||||
import getNodeDocumentLoader from 'jsonld/lib/documentLoaders/node';
|
||||
import * as jsonld from 'jsonld';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { cast } from '@activity-kit/type-utilities';
|
||||
import { RemoteDocument } from 'jsonld/jsonld-spec';
|
||||
import {
|
||||
ACTIVITYSTREAMS_CONTEXT,
|
||||
CONTEXT_DEFINITIONS,
|
||||
DEFAULT_ACTOR_CONTEXT,
|
||||
} from './globals';
|
||||
|
||||
/**
|
||||
* Compact a plain JSON object using known JSON-LD contexts, utilizing the
|
||||
* {@link jsonld} library. If the JSON object does not have a context, a
|
||||
* default context with the known contexts will be applied.
|
||||
*
|
||||
* @returns The compacted JSON-LD object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#compacted-document-form
|
||||
*/
|
||||
export async function compactJsonObject(
|
||||
object: Record<string, unknown>,
|
||||
): Promise<Record<string, unknown> | null> {
|
||||
const document = { ...object };
|
||||
|
||||
if (!('@context' in document)) {
|
||||
document['@context'] = DEFAULT_ACTOR_CONTEXT;
|
||||
}
|
||||
|
||||
const result = await jsonld.compact(
|
||||
document,
|
||||
{
|
||||
'@context': ACTIVITYSTREAMS_CONTEXT,
|
||||
},
|
||||
{
|
||||
documentLoader: customLoader,
|
||||
},
|
||||
);
|
||||
|
||||
return cast.isPlainObject(result) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom document loader for JSON-LD that uses cached contexts.
|
||||
*
|
||||
* Bundling the contexts saves on the number of requests made when parsing
|
||||
* received JSON-LD documents.
|
||||
*
|
||||
* Based on the JSON-LD library's node document loader.
|
||||
*
|
||||
* @returns The remote JSON-LD document.
|
||||
*/
|
||||
async function customLoader(
|
||||
url: string,
|
||||
callback: (err: Error, remoteDoc: RemoteDocument) => void,
|
||||
): Promise<RemoteDocument> {
|
||||
const nodeDocumentLoader = getNodeDocumentLoader();
|
||||
|
||||
if (!nodeDocumentLoader) {
|
||||
throw new Error('nodeDocumentLoader is not defined');
|
||||
}
|
||||
|
||||
const contextUrl = Object.keys(CONTEXT_DEFINITIONS).find(
|
||||
(key) => key === url,
|
||||
);
|
||||
|
||||
if (contextUrl) {
|
||||
return {
|
||||
contextUrl: undefined,
|
||||
document: {
|
||||
'@context': CONTEXT_DEFINITIONS[contextUrl],
|
||||
},
|
||||
documentUrl: contextUrl,
|
||||
};
|
||||
}
|
||||
|
||||
return nodeDocumentLoader(url, callback);
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import * as jsonld from 'jsonld';
|
||||
// See types/jsonldDocumentLoader.d.ts
|
||||
import getNodeDocumentLoader from 'jsonld/lib/documentLoaders/node';
|
||||
import { RemoteDocument, Context } from 'jsonld/jsonld-spec';
|
||||
import { CONTEXT_DEFINITIONS, DEFAULT_CONTEXT } from './globals';
|
||||
import { convertJsonToEntity } from './convertJsonToEntity';
|
||||
import { applyContext } from './applyContext';
|
||||
|
||||
/**
|
||||
* Converts a JSON-LD object to a compacted ActivityPub entity.
|
||||
*
|
||||
* First, the JSON-LD object is compacted using the ActivityStreams context.
|
||||
* Then, the compacted object is converted to an ActivityPub Entity. Finally,
|
||||
* an updated context is applied to the Entity.
|
||||
*
|
||||
* @note This does follow the rules of JSON-LD compaction, as it utilizes the
|
||||
* `jsonld` library to compact the JSON-LD object.
|
||||
*
|
||||
* @returns The ActivityPub entity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#compacted-document-form
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const jsonLd = {
|
||||
* '@context': {
|
||||
* "schema": 'https://schema.org/',
|
||||
* "as": "https://www.w3.org/ns/activitystreams",
|
||||
* },
|
||||
* '@id': 'https://example.com/note/1',
|
||||
* '@type': ['as:Note', 'schema:CreativeWork'],
|
||||
* 'schema:PropertyValue': {
|
||||
* 'schema:name': 'Location',
|
||||
* 'schema:value': 'Earth',
|
||||
* },
|
||||
* 'schema:name': 'My First Note',
|
||||
* 'ap:summary': 'My First Note',
|
||||
* };
|
||||
*
|
||||
* const entity = await convertJsonLdToEntity(jsonLd);
|
||||
*
|
||||
* console.log(entity);
|
||||
* // {
|
||||
* // '@context': [
|
||||
* // 'https://www.w3.org/ns/activitystreams',
|
||||
* // 'https://w3id.org/security/v1',
|
||||
* // {
|
||||
* // 'schema:PropertyValue': 'https://schema.org/PropertyValue',
|
||||
* // 'schema:value': 'https://schema.org/value',
|
||||
* // 'schema:name': 'https://schema.org/name',
|
||||
* // },
|
||||
* // ],
|
||||
* // type: 'Person',
|
||||
* // id: 'https://example.com/note/1',
|
||||
* // name: 'My First Note',
|
||||
* // summary: 'My First Note',
|
||||
* // 'schema:propertyValue': {
|
||||
* // 'schema:name': 'Location',
|
||||
* // 'schema:value': 'Earth',
|
||||
* // },
|
||||
* // }
|
||||
* ```
|
||||
*/
|
||||
export async function convertJsonLdToEntity(
|
||||
document: jsonld.JsonLdDocument,
|
||||
): Promise<AP.Entity | null> {
|
||||
const ctx = DEFAULT_CONTEXT;
|
||||
const result = await jsonld.compact(document, ctx, {
|
||||
documentLoader: customLoader,
|
||||
});
|
||||
|
||||
const converted = convertJsonToEntity(result);
|
||||
|
||||
if (!converted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
delete converted['@context'];
|
||||
|
||||
return applyContext(converted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom document loader for JSON-LD that uses cached contexts.
|
||||
*
|
||||
* Bundling the contexts saves on the number of requests made when parsing
|
||||
* received JSON-LD documents.
|
||||
*
|
||||
* Based on the JSON-LD library's node document loader.
|
||||
*
|
||||
* @returns The remote JSON-LD document.
|
||||
*/
|
||||
async function customLoader(
|
||||
url: string,
|
||||
callback: (err: Error, remoteDoc: RemoteDocument) => void,
|
||||
): Promise<RemoteDocument> {
|
||||
const nodeDocumentLoader = getNodeDocumentLoader();
|
||||
|
||||
if (!nodeDocumentLoader) {
|
||||
throw new Error('nodeDocumentLoader is not defined');
|
||||
}
|
||||
|
||||
const contextUrl = Object.keys(CONTEXT_DEFINITIONS).find(
|
||||
(key) => key === url,
|
||||
);
|
||||
|
||||
if (contextUrl) {
|
||||
return {
|
||||
contextUrl: undefined,
|
||||
document: {
|
||||
'@context': CONTEXT_DEFINITIONS[contextUrl],
|
||||
},
|
||||
documentUrl: contextUrl,
|
||||
};
|
||||
}
|
||||
|
||||
return nodeDocumentLoader(url, callback);
|
||||
}
|
|
@ -47,14 +47,14 @@ export const LOCAL_DOMAIN = `${PROTOCOL}//${LOCAL_HOSTNAME}${
|
|||
}`;
|
||||
|
||||
/**
|
||||
* The JSON-LD context key.
|
||||
* The JSON-LD context property key.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#the-context
|
||||
*/
|
||||
export const CONTEXT_KEY = '@context';
|
||||
|
||||
/**
|
||||
* The JSON-LD context for ActivityPub.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#jsonld-context
|
||||
*/
|
||||
export const ACTIVITYSTREAMS_CONTEXT = 'https://www.w3.org/ns/activitystreams';
|
||||
|
||||
|
@ -63,7 +63,7 @@ export const ACTIVITYSTREAMS_CONTEXT = 'https://www.w3.org/ns/activitystreams';
|
|||
*
|
||||
* Used for signing and verifying signatures.
|
||||
*
|
||||
* @see https://w3id.org/security/v1
|
||||
* @see https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.html
|
||||
*/
|
||||
export const W3ID_SECURITY_CONTEXT = 'https://w3id.org/security/v1';
|
||||
|
||||
|
@ -198,17 +198,31 @@ export const HTML_CONTENT_TYPE = 'text/html';
|
|||
export const USERNAME_REGEXP = /^[\w\d]{3,12}$/;
|
||||
|
||||
/**
|
||||
* The default JSON-LD context for ActivityPub Entities.
|
||||
* The default JSON-LD context for ActivityPub Actors.
|
||||
*
|
||||
* @see {@link ACTIVITYSTREAMS_CONTEXT}
|
||||
* @see {@link W3ID_SECURITY_CONTEXT}
|
||||
* @see {@link SCHEMA_ORG_CONTEXT}
|
||||
*/
|
||||
export const DEFAULT_CONTEXT = {
|
||||
'@vocab': ACTIVITYSTREAMS_CONTEXT,
|
||||
sec: W3ID_SECURITY_CONTEXT,
|
||||
schema: SCHEMA_ORG_CONTEXT,
|
||||
};
|
||||
export const DEFAULT_ACTOR_CONTEXT = [
|
||||
W3ID_SECURITY_CONTEXT,
|
||||
ACTIVITYSTREAMS_CONTEXT,
|
||||
{
|
||||
schema: SCHEMA_ORG_CONTEXT,
|
||||
},
|
||||
];
|
||||
|
||||
export const DEFAULT_CONTEXT_AS_URLS = Object.fromEntries(
|
||||
Object.entries(DEFAULT_CONTEXT).map(([key, value]) => [key, new URL(value)]),
|
||||
/**
|
||||
* The default JSON-LD context for ActivityPub Actors, with instances of URL in
|
||||
* place of strings.
|
||||
*
|
||||
export const DEFAULT_ACTOR_CONTEXT_AS_URLS = Object.fromEntries(
|
||||
Object.entries(DEFAULT_ACTOR_CONTEXT).map(([key, value]) => [
|
||||
key,
|
||||
new URL(value),
|
||||
]),
|
||||
);
|
||||
*/
|
||||
|
||||
/**
|
||||
* Express-style route parameters.
|
||||
|
|
|
@ -2,13 +2,10 @@ export * from './globals';
|
|||
export { applyContext } from './applyContext';
|
||||
export { cleanProps } from './cleanProps';
|
||||
export { compressEntity } from './compressEntity';
|
||||
export { convertJsonLdToEntity } from './convertJsonLdToEntity';
|
||||
export { compactJsonObject } from './compactJsonObject';
|
||||
export { convertJsonToEntity } from './convertJsonToEntity';
|
||||
export { convertEntityToJson } from './convertEntityToJson';
|
||||
export { getCollectionNameByUrl } from './getCollectionNameByUrl';
|
||||
export { getId } from './getId';
|
||||
export { getEntity } from './getEntity';
|
||||
export { parseStream } from './parseStream';
|
||||
export { streamToString } from './streamToString';
|
||||
export { deduplicateUrls } from './deduplicateUrls';
|
||||
export { isLocal } from './isLocal';
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import type { IncomingMessage } from 'http';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { convertJsonLdToEntity } from './convertJsonLdToEntity';
|
||||
import { streamToString } from './streamToString';
|
||||
|
||||
/**
|
||||
* Parse an HTTP stream into an Entity.
|
||||
*
|
||||
* @returns The Entity, or null if not found.
|
||||
*
|
||||
* @todo This is being depricated in favor of having adapters handle this.
|
||||
*/
|
||||
export async function parseStream(
|
||||
req: IncomingMessage,
|
||||
): Promise<AP.Entity | null> {
|
||||
return await convertJsonLdToEntity(JSON.parse(await streamToString(req)));
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
import { IncomingMessage } from 'http';
|
||||
|
||||
/**
|
||||
* Converts an HTTP stream to a string.
|
||||
*
|
||||
* @returns The string.
|
||||
*
|
||||
* @todo This is being depricated in favor of having adapters handle this.
|
||||
*/
|
||||
export async function streamToString(stream: IncomingMessage): Promise<string> {
|
||||
if (stream) {
|
||||
const chunks = [];
|
||||
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(Buffer.from(chunk));
|
||||
}
|
||||
|
||||
return Buffer.concat(chunks).toString('utf-8');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
import 'jasmine';
|
||||
|
||||
import { compactJsonObject } from '../src/compactJsonObject';
|
||||
|
||||
describe('compactJsonObject', () => {
|
||||
it('should maintain JSON object', async () => {
|
||||
const compacted = await compactJsonObject({
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'https://example.com',
|
||||
type: 'Person',
|
||||
name: 'Example',
|
||||
});
|
||||
|
||||
expect(compacted).toEqual({
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'https://example.com',
|
||||
type: 'Person',
|
||||
name: 'Example',
|
||||
});
|
||||
});
|
||||
|
||||
it('should compact plain JSON object', async () => {
|
||||
const compacted = await compactJsonObject({
|
||||
id: 'https://example.com',
|
||||
type: 'Person',
|
||||
name: 'Example',
|
||||
image: {
|
||||
type: 'Image',
|
||||
url: 'https://example.com/image.png',
|
||||
},
|
||||
});
|
||||
|
||||
expect(compacted).toEqual({
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'https://example.com',
|
||||
type: 'Person',
|
||||
name: 'Example',
|
||||
image: {
|
||||
type: 'Image',
|
||||
url: 'https://example.com/image.png',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue