@atproto/oauth-scopes 0.3.1 → 0.4.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/atproto-oauth-scope.js +28 -35
- package/dist/atproto-oauth-scope.js.map +1 -1
- package/dist/index.js +11 -27
- package/dist/index.js.map +1 -1
- package/dist/lib/lexicon.js +1 -2
- package/dist/lib/mime.js +4 -10
- package/dist/lib/mime.js.map +1 -1
- package/dist/lib/nsid.js +2 -6
- package/dist/lib/nsid.js.map +1 -1
- package/dist/lib/parser.js +6 -31
- package/dist/lib/parser.js.map +1 -1
- package/dist/lib/resource-permission.js +1 -2
- package/dist/lib/syntax-lexicon.js +2 -11
- package/dist/lib/syntax-lexicon.js.map +1 -1
- package/dist/lib/syntax-string.js +6 -25
- package/dist/lib/syntax-string.js.map +1 -1
- package/dist/lib/syntax.js +2 -6
- package/dist/lib/syntax.js.map +1 -1
- package/dist/lib/util.js +3 -8
- package/dist/lib/util.js.map +1 -1
- package/dist/scope-missing-error.js +5 -29
- package/dist/scope-missing-error.js.map +1 -1
- package/dist/scope-permissions-transition.js +2 -6
- package/dist/scope-permissions-transition.js.map +1 -1
- package/dist/scope-permissions.js +19 -29
- package/dist/scope-permissions.js.map +1 -1
- package/dist/scopes/account-permission.js +24 -43
- package/dist/scopes/account-permission.js.map +1 -1
- package/dist/scopes/blob-permission.js +26 -40
- package/dist/scopes/blob-permission.js.map +1 -1
- package/dist/scopes/identity-permission.js +16 -30
- package/dist/scopes/identity-permission.js.map +1 -1
- package/dist/scopes/include-scope.js +35 -54
- package/dist/scopes/include-scope.js.map +1 -1
- package/dist/scopes/repo-permission.js +39 -59
- package/dist/scopes/repo-permission.js.map +1 -1
- package/dist/scopes/rpc-permission.js +28 -50
- package/dist/scopes/rpc-permission.js.map +1 -1
- package/dist/scopes-set.js +19 -23
- package/dist/scopes-set.js.map +1 -1
- package/jest.config.cjs +14 -0
- package/package.json +10 -9
- package/src/scopes/include-scope.test.ts +5 -5
- package/tsconfig.build.tsbuildinfo +1 -1
- package/jest.config.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @atproto/oauth-scopes
|
|
2
2
|
|
|
3
|
+
## 0.4.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
|
|
8
|
+
|
|
9
|
+
- [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
|
|
10
|
+
|
|
11
|
+
Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
|
|
12
|
+
|
|
13
|
+
- [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`.
|
|
14
|
+
|
|
15
|
+
Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b), [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028), [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9)]:
|
|
20
|
+
- @atproto/did@0.4.0-next.0
|
|
21
|
+
- @atproto/syntax@0.6.0-next.0
|
|
22
|
+
|
|
23
|
+
## 0.3.2
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`f7c2610`](https://github.com/bluesky-social/atproto/commit/f7c26103a6d4e24e5bedbb6fd908be140420e0dd), [`f7c2610`](https://github.com/bluesky-social/atproto/commit/f7c26103a6d4e24e5bedbb6fd908be140420e0dd), [`f7c2610`](https://github.com/bluesky-social/atproto/commit/f7c26103a6d4e24e5bedbb6fd908be140420e0dd), [`f7c2610`](https://github.com/bluesky-social/atproto/commit/f7c26103a6d4e24e5bedbb6fd908be140420e0dd), [`f7c2610`](https://github.com/bluesky-social/atproto/commit/f7c26103a6d4e24e5bedbb6fd908be140420e0dd), [`52834ab`](https://github.com/bluesky-social/atproto/commit/52834aba182da8df3611fd9dff924e6c6a3973a7), [`f7c2610`](https://github.com/bluesky-social/atproto/commit/f7c26103a6d4e24e5bedbb6fd908be140420e0dd)]:
|
|
28
|
+
- @atproto/syntax@0.5.0
|
|
29
|
+
|
|
3
30
|
## 0.3.1
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const account_permission_js_1 = require("./scopes/account-permission.js");
|
|
12
|
-
const blob_permission_js_1 = require("./scopes/blob-permission.js");
|
|
13
|
-
const identity_permission_js_1 = require("./scopes/identity-permission.js");
|
|
14
|
-
const include_scope_js_1 = require("./scopes/include-scope.js");
|
|
15
|
-
const repo_permission_js_1 = require("./scopes/repo-permission.js");
|
|
16
|
-
const rpc_permission_js_1 = require("./scopes/rpc-permission.js");
|
|
17
|
-
exports.STATIC_SCOPE_VALUES = Object.freeze([
|
|
1
|
+
import { isScopeStringFor } from './lib/syntax.js';
|
|
2
|
+
import { isNonNullable } from './lib/util.js';
|
|
3
|
+
import { AccountPermission } from './scopes/account-permission.js';
|
|
4
|
+
import { BlobPermission } from './scopes/blob-permission.js';
|
|
5
|
+
import { IdentityPermission } from './scopes/identity-permission.js';
|
|
6
|
+
import { IncludeScope } from './scopes/include-scope.js';
|
|
7
|
+
import { RepoPermission } from './scopes/repo-permission.js';
|
|
8
|
+
import { RpcPermission } from './scopes/rpc-permission.js';
|
|
9
|
+
export { isScopeStringFor };
|
|
10
|
+
export const STATIC_SCOPE_VALUES = Object.freeze([
|
|
18
11
|
'atproto',
|
|
19
12
|
'transition:email',
|
|
20
13
|
'transition:generic',
|
|
21
14
|
'transition:chat.bsky',
|
|
22
15
|
]);
|
|
23
|
-
function isStaticScopeValue(value) {
|
|
24
|
-
return
|
|
16
|
+
export function isStaticScopeValue(value) {
|
|
17
|
+
return STATIC_SCOPE_VALUES.includes(value);
|
|
25
18
|
}
|
|
26
19
|
/**
|
|
27
20
|
* @note This function does not only verify the scope string format (with
|
|
@@ -30,33 +23,33 @@ function isStaticScopeValue(value) {
|
|
|
30
23
|
* excluding scopes that cannot be fully interpreted by the current version of
|
|
31
24
|
* the code.
|
|
32
25
|
*/
|
|
33
|
-
function isAtprotoOauthScope(value) {
|
|
26
|
+
export function isAtprotoOauthScope(value) {
|
|
34
27
|
return (isStaticScopeValue(value) ||
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
AccountPermission.fromString(value) != null ||
|
|
29
|
+
BlobPermission.fromString(value) != null ||
|
|
30
|
+
IdentityPermission.fromString(value) != null ||
|
|
31
|
+
IncludeScope.fromString(value) != null ||
|
|
32
|
+
RepoPermission.fromString(value) != null ||
|
|
33
|
+
RpcPermission.fromString(value) != null);
|
|
41
34
|
}
|
|
42
|
-
function normalizeAtprotoOauthScope(scope) {
|
|
35
|
+
export function normalizeAtprotoOauthScope(scope) {
|
|
43
36
|
return scope
|
|
44
37
|
.split(' ')
|
|
45
38
|
.map(normalizeAtprotoOauthScopeValue)
|
|
46
|
-
.filter(
|
|
39
|
+
.filter(isNonNullable)
|
|
47
40
|
.sort()
|
|
48
41
|
.join(' ');
|
|
49
42
|
}
|
|
50
|
-
function normalizeAtprotoOauthScopeValue(value) {
|
|
43
|
+
export function normalizeAtprotoOauthScopeValue(value) {
|
|
51
44
|
if (isStaticScopeValue(value))
|
|
52
45
|
return value;
|
|
53
46
|
for (const Scope of [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
AccountPermission,
|
|
48
|
+
BlobPermission,
|
|
49
|
+
IdentityPermission,
|
|
50
|
+
IncludeScope,
|
|
51
|
+
RepoPermission,
|
|
52
|
+
RpcPermission,
|
|
60
53
|
]) {
|
|
61
54
|
const parsed = Scope.fromString(value);
|
|
62
55
|
if (parsed)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto-oauth-scope.js","sourceRoot":"","sources":["../src/atproto-oauth-scope.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atproto-oauth-scope.js","sourceRoot":"","sources":["../src/atproto-oauth-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,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AAkB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAE3C,KAAK,MAAM,KAAK,IAAI;QAClB,iBAAiB;QACjB,cAAc;QACd,kBAAkB;QAClB,YAAY;QACZ,cAAc;QACd,aAAa;KACd,EAAE,CAAC;QACF,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QACtC,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAA;IACtC,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { ScopeStringFor, isScopeStringFor } from './lib/syntax.js'\nimport { isNonNullable } from './lib/util.js'\nimport { AccountPermission } from './scopes/account-permission.js'\nimport { BlobPermission } from './scopes/blob-permission.js'\nimport { IdentityPermission } from './scopes/identity-permission.js'\nimport { IncludeScope } from './scopes/include-scope.js'\nimport { RepoPermission } from './scopes/repo-permission.js'\nimport { RpcPermission } from './scopes/rpc-permission.js'\n\nexport { type ScopeStringFor, isScopeStringFor }\n\nexport const STATIC_SCOPE_VALUES = Object.freeze([\n 'atproto',\n 'transition:email',\n 'transition:generic',\n 'transition:chat.bsky',\n] as const)\n\nexport type StaticScopeValue = (typeof STATIC_SCOPE_VALUES)[number]\nexport function isStaticScopeValue(value: string): value is StaticScopeValue {\n return (STATIC_SCOPE_VALUES as readonly string[]).includes(value)\n}\n\nexport type AtprotoOauthScope =\n | StaticScopeValue\n | ScopeStringFor<'account'>\n | ScopeStringFor<'blob'>\n | ScopeStringFor<'identity'>\n | ScopeStringFor<'include'>\n | ScopeStringFor<'repo'>\n | ScopeStringFor<'rpc'>\n\n/**\n * @note This function does not only verify the scope string format (with\n * {@link isScopeStringFor}), but also checks if the provided parameters are\n * valid according to the respective scope syntax definition. This allows\n * excluding scopes that cannot be fully interpreted by the current version of\n * the code.\n */\nexport function isAtprotoOauthScope(value: string): value is AtprotoOauthScope {\n return (\n isStaticScopeValue(value) ||\n AccountPermission.fromString(value) != null ||\n BlobPermission.fromString(value) != null ||\n IdentityPermission.fromString(value) != null ||\n IncludeScope.fromString(value) != null ||\n RepoPermission.fromString(value) != null ||\n RpcPermission.fromString(value) != null\n )\n}\n\nexport function normalizeAtprotoOauthScope(scope: string) {\n return scope\n .split(' ')\n .map(normalizeAtprotoOauthScopeValue)\n .filter(isNonNullable)\n .sort()\n .join(' ')\n}\n\nexport function normalizeAtprotoOauthScopeValue(\n value: string,\n): AtprotoOauthScope | null {\n if (isStaticScopeValue(value)) return value\n\n for (const Scope of [\n AccountPermission,\n BlobPermission,\n IdentityPermission,\n IncludeScope,\n RepoPermission,\n RpcPermission,\n ]) {\n const parsed = Scope.fromString(value)\n if (parsed) return parsed.toString()\n }\n\n return null\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./atproto-oauth-scope.js"), exports);
|
|
18
|
-
__exportStar(require("./scope-missing-error.js"), exports);
|
|
19
|
-
__exportStar(require("./scope-permissions-transition.js"), exports);
|
|
20
|
-
__exportStar(require("./scope-permissions.js"), exports);
|
|
21
|
-
__exportStar(require("./scopes-set.js"), exports);
|
|
22
|
-
__exportStar(require("./scopes/account-permission.js"), exports);
|
|
23
|
-
__exportStar(require("./scopes/blob-permission.js"), exports);
|
|
24
|
-
__exportStar(require("./scopes/identity-permission.js"), exports);
|
|
25
|
-
__exportStar(require("./scopes/include-scope.js"), exports);
|
|
26
|
-
__exportStar(require("./scopes/repo-permission.js"), exports);
|
|
27
|
-
__exportStar(require("./scopes/rpc-permission.js"), exports);
|
|
1
|
+
export * from './atproto-oauth-scope.js';
|
|
2
|
+
export * from './scope-missing-error.js';
|
|
3
|
+
export * from './scope-permissions-transition.js';
|
|
4
|
+
export * from './scope-permissions.js';
|
|
5
|
+
export * from './scopes-set.js';
|
|
6
|
+
export * from './scopes/account-permission.js';
|
|
7
|
+
export * from './scopes/blob-permission.js';
|
|
8
|
+
export * from './scopes/identity-permission.js';
|
|
9
|
+
export * from './scopes/include-scope.js';
|
|
10
|
+
export * from './scopes/repo-permission.js';
|
|
11
|
+
export * from './scopes/rpc-permission.js';
|
|
28
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AAExC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mCAAmC,CAAA;AACjD,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAE/B,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,4BAA4B,CAAA","sourcesContent":["export * from './atproto-oauth-scope.js'\n\nexport * from './scope-missing-error.js'\nexport * from './scope-permissions-transition.js'\nexport * from './scope-permissions.js'\nexport * from './scopes-set.js'\n\nexport * from './scopes/account-permission.js'\nexport * from './scopes/blob-permission.js'\nexport * from './scopes/identity-permission.js'\nexport * from './scopes/include-scope.js'\nexport * from './scopes/repo-permission.js'\nexport * from './scopes/rpc-permission.js'\n"]}
|
package/dist/lib/lexicon.js
CHANGED
package/dist/lib/mime.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// @TODO Refactor in shared location for use with other @atproto packages
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.isMime = isMime;
|
|
5
|
-
exports.isAccept = isAccept;
|
|
6
|
-
exports.matchesAccept = matchesAccept;
|
|
7
|
-
exports.matchesAnyAccept = matchesAnyAccept;
|
|
8
2
|
function isStringSlashString(value) {
|
|
9
3
|
const slashIndex = value.indexOf('/');
|
|
10
4
|
if (slashIndex === -1)
|
|
@@ -19,10 +13,10 @@ function isStringSlashString(value) {
|
|
|
19
13
|
return false; // Spaces are not allowed
|
|
20
14
|
return true;
|
|
21
15
|
}
|
|
22
|
-
function isMime(value) {
|
|
16
|
+
export function isMime(value) {
|
|
23
17
|
return isStringSlashString(value) && !value.includes('*');
|
|
24
18
|
}
|
|
25
|
-
function isAccept(value) {
|
|
19
|
+
export function isAccept(value) {
|
|
26
20
|
if (typeof value !== 'string')
|
|
27
21
|
return false;
|
|
28
22
|
if (value === '*/*')
|
|
@@ -45,7 +39,7 @@ function matchesAcceptUnsafe(accept, mime) {
|
|
|
45
39
|
}
|
|
46
40
|
return accept === mime;
|
|
47
41
|
}
|
|
48
|
-
function matchesAccept(accept, mime) {
|
|
42
|
+
export function matchesAccept(accept, mime) {
|
|
49
43
|
return isMime(mime) && matchesAcceptUnsafe(accept, mime);
|
|
50
44
|
}
|
|
51
45
|
/**
|
|
@@ -61,7 +55,7 @@ function matchesAnyAcceptUnsafe(acceptable, mime) {
|
|
|
61
55
|
}
|
|
62
56
|
return false;
|
|
63
57
|
}
|
|
64
|
-
function matchesAnyAccept(acceptable, mime) {
|
|
58
|
+
export function matchesAnyAccept(acceptable, mime) {
|
|
65
59
|
return isMime(mime) && matchesAnyAcceptUnsafe(acceptable, mime);
|
|
66
60
|
}
|
|
67
61
|
//# sourceMappingURL=mime.js.map
|
package/dist/lib/mime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../src/lib/mime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../src/lib/mime.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,SAAS,mBAAmB,CAAC,KAAa;IACxC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAErC,IAAI,UAAU,KAAK,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA,CAAC,gBAAgB;IACpD,IAAI,UAAU,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA,CAAC,mCAAmC;IACtE,IAAI,UAAU,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA,CAAC,mCAAmC;IACrF,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA,CAAC,sBAAsB;IAC5E,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA,CAAC,yBAAyB;IAE/D,OAAO,IAAI,CAAA;AACb,CAAC;AAID,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,OAAO,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAC3D,CAAC;AAID,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,IAAI,CAAA,CAAC,qCAAqC;IACtE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC7C,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AACrD,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,MAAc,EAAE,IAAU;IACrD,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7C,CAAC;IACD,OAAO,MAAM,KAAK,IAAI,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,IAAY;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAC1D,CAAC;AAED;;;;GAIG;AACH,SAAS,sBAAsB,CAC7B,UAA4B,EAC5B,IAAU;IAEV,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,IAAI,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,UAA4B,EAC5B,IAAY;IAEZ,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACjE,CAAC","sourcesContent":["// @TODO Refactor in shared location for use with other @atproto packages\n\nfunction isStringSlashString(value: string): value is `${string}/${string}` {\n const slashIndex = value.indexOf('/')\n\n if (slashIndex === -1) return false // Missing slash\n if (slashIndex === 0) return false // No leading part before the slash\n if (slashIndex === value.length - 1) return false // No trailing part after the slash\n if (value.includes('/', slashIndex + 1)) return false // More than one slash\n if (value.includes(' ')) return false // Spaces are not allowed\n\n return true\n}\n\nexport type Mime = `${string}/${string}`\n\nexport function isMime(value: string): value is Mime {\n return isStringSlashString(value) && !value.includes('*')\n}\n\nexport type Accept = '*/*' | `${string}/*` | Mime\n\nexport function isAccept(value: unknown): value is Accept {\n if (typeof value !== 'string') return false\n if (value === '*/*') return true // Fast path for the most common case\n if (!isStringSlashString(value)) return false\n return !value.includes('*') || value.endsWith('/*')\n}\n\n/**\n * @note \"unsafe\" in that it does not check if either {@link accept} or\n * {@link mime} are actually valid values (and could, therefore, lead to false\n * positives if forged values are used).\n */\nfunction matchesAcceptUnsafe(accept: Accept, mime: Mime): boolean {\n if (accept === '*/*') {\n return true\n }\n if (accept.endsWith('/*')) {\n return mime.startsWith(accept.slice(0, -1))\n }\n return accept === mime\n}\n\nexport function matchesAccept(accept: Accept, mime: string): boolean {\n return isMime(mime) && matchesAcceptUnsafe(accept, mime)\n}\n\n/**\n * @note \"unsafe\" in that it does not check if either {@link accept} or\n * {@link mime} are actually valid values (and could, therefore, lead to false\n * positives if forged values are used).\n */\nfunction matchesAnyAcceptUnsafe(\n acceptable: Iterable<Accept>,\n mime: Mime,\n): boolean {\n for (const accept of acceptable) {\n if (matchesAcceptUnsafe(accept, mime)) {\n return true\n }\n }\n return false\n}\n\nexport function matchesAnyAccept(\n acceptable: Iterable<Accept>,\n mime: string,\n): boolean {\n return isMime(mime) && matchesAnyAcceptUnsafe(acceptable, mime)\n}\n"]}
|
package/dist/lib/nsid.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.isNsid = void 0;
|
|
4
|
-
const syntax_1 = require("@atproto/syntax");
|
|
5
|
-
const isNsid = (v) => typeof v === 'string' && (0, syntax_1.isValidNsid)(v);
|
|
6
|
-
exports.isNsid = isNsid;
|
|
1
|
+
import { isValidNsid } from '@atproto/syntax';
|
|
2
|
+
export const isNsid = (v) => typeof v === 'string' && isValidNsid(v);
|
|
7
3
|
//# sourceMappingURL=nsid.js.map
|
package/dist/lib/nsid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nsid.js","sourceRoot":"","sources":["../../src/lib/nsid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nsid.js","sourceRoot":"","sources":["../../src/lib/nsid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAU,EAAa,EAAE,CAC9C,OAAO,CAAC,KAAK,QAAQ,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA","sourcesContent":["import { isValidNsid } from '@atproto/syntax'\n\nexport type Nsid = `${string}.${string}.${string}`\nexport const isNsid = (v: unknown): v is Nsid =>\n typeof v === 'string' && isValidNsid(v)\n"]}
|
package/dist/lib/parser.js
CHANGED
|
@@ -1,33 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Parser = void 0;
|
|
4
|
-
const syntax_string_js_1 = require("./syntax-string.js");
|
|
5
|
-
class Parser {
|
|
1
|
+
import { ScopeStringSyntax } from './syntax-string.js';
|
|
2
|
+
export class Parser {
|
|
6
3
|
constructor(prefix, schema, positionalName) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
writable: true,
|
|
11
|
-
value: prefix
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(this, "schema", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: schema
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(this, "positionalName", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: positionalName
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, "schemaKeys", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: void 0
|
|
30
|
-
});
|
|
4
|
+
this.prefix = prefix;
|
|
5
|
+
this.schema = schema;
|
|
6
|
+
this.positionalName = positionalName;
|
|
31
7
|
this.schemaKeys = new Set(Object.keys(schema));
|
|
32
8
|
}
|
|
33
9
|
format(values) {
|
|
@@ -73,7 +49,7 @@ class Parser {
|
|
|
73
49
|
}
|
|
74
50
|
}
|
|
75
51
|
}
|
|
76
|
-
return new
|
|
52
|
+
return new ScopeStringSyntax(this.prefix, positional, params).toString();
|
|
77
53
|
}
|
|
78
54
|
// @NOTE If we needed to ever have more detailed reason as to why parsing
|
|
79
55
|
// fails, this function could easily be updated to return a
|
|
@@ -133,7 +109,6 @@ class Parser {
|
|
|
133
109
|
return result;
|
|
134
110
|
}
|
|
135
111
|
}
|
|
136
|
-
exports.Parser = Parser;
|
|
137
112
|
/**
|
|
138
113
|
* Two param arrays are considered equal if they contain the same values,
|
|
139
114
|
* regardless of the order and duplicates.
|
package/dist/lib/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAsCtD,MAAM,OAAO,MAAM;IAGjB,YACkB,MAAS,EACT,MAAS,EACT,cAAiC;QAFjC,WAAM,GAAN,MAAM,CAAG;QACT,WAAM,GAAN,MAAM,CAAG;QACT,mBAAc,GAAd,cAAc,CAAmB;QAEjD,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,CAAC,MAAsB;QAC3B,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA;QACpC,IAAI,UAAU,GAAuB,SAAS,CAAA;QAE9C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,MA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AAK,CAAA;IACzD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { ScopeStringSyntax } from './syntax-string.js'\nimport { NeRoArray, ParamValue, ScopeSyntax } from './syntax.js'\n\ntype InferParamPredicate<T extends (value: ParamValue) => boolean> =\n T extends ((value: ParamValue) => value is infer U extends ParamValue)\n ? U\n : ParamValue\n\ntype ParamsSchema = Record<\n string,\n | {\n multiple: false\n required: boolean\n default?: ParamValue\n normalize?: (value: ParamValue) => ParamValue\n validate: (value: ParamValue) => boolean\n }\n | {\n multiple: true\n required: boolean\n default?: NeRoArray<ParamValue>\n normalize?: (value: NeRoArray<ParamValue>) => NeRoArray<ParamValue>\n validate: (value: ParamValue) => boolean\n }\n>\n\ntype InferParams<S extends ParamsSchema> = {\n [K in keyof S]:\n | (S[K]['required'] extends true\n ? never\n : 'default' extends keyof S[K]\n ? S[K]['default']\n : undefined)\n | (S[K]['multiple'] extends true\n ? NeRoArray<InferParamPredicate<S[K]['validate']>>\n : InferParamPredicate<S[K]['validate']>)\n} & NonNullable<unknown>\n\nexport class Parser<P extends string, S extends ParamsSchema> {\n public readonly schemaKeys: ReadonlySet<keyof S & string>\n\n constructor(\n public readonly prefix: P,\n public readonly schema: S,\n public readonly positionalName?: keyof S & string,\n ) {\n this.schemaKeys = new Set(Object.keys(schema))\n }\n\n format(values: InferParams<S>) {\n const params = new URLSearchParams()\n let positional: string | undefined = undefined\n\n for (const key of this.schemaKeys) {\n const value = values[key]\n // Ignore undefined values\n if (value === undefined) continue\n\n const schema = this.schema[key]\n\n // Normalize the value if a normalization function is provided\n const normalized = schema.normalize\n ? schema.normalize(value as any)\n : value\n\n // Ignore values that are equal to the default value\n if (!schema.required) {\n if (schema.default === normalized) continue\n if (\n schema.multiple &&\n schema.default &&\n arrayParamEquals(schema.default, normalized as NeRoArray<string>)\n ) {\n continue\n }\n }\n\n if (Array.isArray(normalized)) {\n if (key === this.positionalName && normalized.length === 1) {\n positional = String(normalized[0]!)\n } else {\n // remove duplicates\n const unique = new Set(normalized.map(String))\n for (const v of unique) params.append(key, v)\n }\n } else {\n if (key === this.positionalName) {\n positional = String(normalized)\n } else {\n params.set(key, String(normalized))\n }\n }\n }\n\n return new ScopeStringSyntax(this.prefix, positional, params).toString()\n }\n\n // @NOTE If we needed to ever have more detailed reason as to why parsing\n // fails, this function could easily be updated to return a\n // ValidationResult<T> type that explains the reason for failure.\n parse(syntax: ScopeSyntax<P>) {\n // @NOTE no need to check prefix, since the typing (P generic) already\n // ensures it matches\n\n for (const key of syntax.keys()) {\n if (!this.schemaKeys.has(key)) return null\n }\n\n const result: Record<\n string,\n undefined | ParamValue | NeRoArray<ParamValue>\n > = Object.create(null)\n\n for (const key of this.schemaKeys) {\n const definition = this.schema[key]\n\n const param = definition.multiple\n ? syntax.getMulti(key)\n : syntax.getSingle(key)\n\n if (param === null) {\n return null // Value is not valid\n } else if (param !== undefined) {\n if (key === this.positionalName && syntax.positional !== undefined) {\n // Positional parameter cannot be used with named parameters\n return null\n }\n\n if (definition.multiple) {\n // Empty array is not valid\n if (!(param as ParamValue[]).length) return null\n if (!(param as ParamValue[]).every(definition.validate)) {\n return null\n }\n } else {\n if (!definition.validate(param as ParamValue)) {\n return null\n }\n }\n\n result[key] = param as ParamValue | NeRoArray<ParamValue>\n } else if (\n key === this.positionalName &&\n syntax.positional !== undefined\n ) {\n // No named parameters found, but there is a positional parameter\n const { positional } = syntax\n if (!definition.validate(positional)) {\n return null\n }\n result[key] = definition.multiple ? [positional] : positional\n } else if (definition.required) {\n return null\n } else {\n result[key] = definition.default\n }\n }\n\n return result as InferParams<S>\n }\n}\n\n/**\n * Two param arrays are considered equal if they contain the same values,\n * regardless of the order and duplicates.\n * @param a - The first array to compare.\n * @param b - The second array to compare.\n */\nfunction arrayParamEquals(\n a: readonly unknown[],\n b: readonly unknown[],\n): boolean {\n for (const item of a) if (!b.includes(item)) return false\n for (const item of b) if (!a.includes(item)) return false\n return true\n}\n"]}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LexPermissionSyntax = void 0;
|
|
4
1
|
const isArray = Array.isArray;
|
|
5
2
|
/**
|
|
6
3
|
* Translates a {@link LexiconPermission} into a {@link ScopeSyntax}.
|
|
7
4
|
*/
|
|
8
|
-
class LexPermissionSyntax {
|
|
5
|
+
export class LexPermissionSyntax {
|
|
9
6
|
constructor(lexPermission) {
|
|
10
|
-
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: lexPermission
|
|
15
|
-
});
|
|
7
|
+
this.lexPermission = lexPermission;
|
|
16
8
|
}
|
|
17
9
|
get prefix() {
|
|
18
10
|
return this.lexPermission.resource;
|
|
@@ -55,5 +47,4 @@ class LexPermissionSyntax {
|
|
|
55
47
|
return this.lexPermission;
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
|
-
exports.LexPermissionSyntax = LexPermissionSyntax;
|
|
59
50
|
//# sourceMappingURL=syntax-lexicon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-lexicon.js","sourceRoot":"","sources":["../../src/lib/syntax-lexicon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"syntax-lexicon.js","sourceRoot":"","sources":["../../src/lib/syntax-lexicon.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,GAAoD,KAAK,CAAC,OAAO,CAAA;AAE9E;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAG9B,YAAqB,aAAmC;QAAnC,kBAAa,GAAb,aAAa,CAAsB;IAAG,CAAC;IAE5D,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAA;IACpC,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,GAAG,CAAC,GAAW;QACb,2BAA2B;QAC3B,IAAI,GAAG,KAAK,MAAM;YAAE,OAAO,SAAS,CAAA;QACpC,IAAI,GAAG,KAAK,UAAU;YAAE,OAAO,SAAS,CAAA;QAExC,iDAAiD;QACjD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;QAE7D,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;IAED,CAAC,IAAI;QACH,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAClD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;gBAAE,MAAM,GAAG,CAAA;QAC5C,CAAC;IACH,CAAC;IAED,SAAS,CAAC,GAAW;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QAC/B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAA;QACzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QAChC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;CACF","sourcesContent":["import { LexiconPermission } from './lexicon.js'\nimport { ScopeSyntax } from './syntax.js'\n\nconst isArray: (value: unknown) => value is readonly unknown[] = Array.isArray\n\n/**\n * Translates a {@link LexiconPermission} into a {@link ScopeSyntax}.\n */\nexport class LexPermissionSyntax<P extends string = string>\n implements ScopeSyntax<P>\n{\n constructor(readonly lexPermission: LexiconPermission<P>) {}\n\n get prefix() {\n return this.lexPermission.resource\n }\n\n get positional() {\n return undefined\n }\n\n get(key: string) {\n // Ignore reserved keywords\n if (key === 'type') return undefined\n if (key === 'resource') return undefined\n\n // Ignore inherited properties (toString(), etc.)\n if (!Object.hasOwn(this.lexPermission, key)) return undefined\n\n return this.lexPermission[key]\n }\n\n *keys() {\n for (const key of Object.keys(this.lexPermission)) {\n if (this.get(key) !== undefined) yield key\n }\n }\n\n getSingle(key: string) {\n const value = this.get(key)\n if (isArray(value)) return null\n return value\n }\n\n getMulti(key: string) {\n const value = this.get(key)\n if (value === undefined) return undefined\n if (!isArray(value)) return null\n return value\n }\n\n toJSON() {\n return this.lexPermission\n }\n}\n"]}
|
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ScopeStringSyntax = void 0;
|
|
4
|
-
const util_js_1 = require("./util.js");
|
|
1
|
+
import { minIdx } from './util.js';
|
|
5
2
|
/**
|
|
6
3
|
* Translates a scope string into a {@link ScopeSyntax}.
|
|
7
4
|
*/
|
|
8
|
-
class ScopeStringSyntax {
|
|
5
|
+
export class ScopeStringSyntax {
|
|
9
6
|
constructor(prefix, positional, params) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
writable: true,
|
|
14
|
-
value: prefix
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(this, "positional", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: positional
|
|
21
|
-
});
|
|
22
|
-
Object.defineProperty(this, "params", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: params
|
|
27
|
-
});
|
|
7
|
+
this.prefix = prefix;
|
|
8
|
+
this.positional = positional;
|
|
9
|
+
this.params = params;
|
|
28
10
|
}
|
|
29
11
|
*keys() {
|
|
30
12
|
if (this.params)
|
|
@@ -56,7 +38,7 @@ class ScopeStringSyntax {
|
|
|
56
38
|
static fromString(scopeValue) {
|
|
57
39
|
const paramIdx = scopeValue.indexOf('?');
|
|
58
40
|
const colonIdx = scopeValue.indexOf(':');
|
|
59
|
-
const prefixEnd =
|
|
41
|
+
const prefixEnd = minIdx(paramIdx, colonIdx);
|
|
60
42
|
// No param or positional
|
|
61
43
|
if (prefixEnd === -1) {
|
|
62
44
|
return new ScopeStringSyntax(scopeValue);
|
|
@@ -77,7 +59,6 @@ class ScopeStringSyntax {
|
|
|
77
59
|
return new ScopeStringSyntax(prefix, positional, params);
|
|
78
60
|
}
|
|
79
61
|
}
|
|
80
|
-
exports.ScopeStringSyntax = ScopeStringSyntax;
|
|
81
62
|
/**
|
|
82
63
|
* Set of characters that are allowed in scope components without encoding. This
|
|
83
64
|
* is used to normalize scope components.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-string.js","sourceRoot":"","sources":["../../src/lib/syntax-string.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"syntax-string.js","sourceRoot":"","sources":["../../src/lib/syntax-string.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAElC;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC5B,YACW,MAAS,EACT,UAAmB,EACnB,MAAkC;QAFlC,WAAM,GAAN,MAAM,CAAG;QACT,eAAU,GAAV,UAAU,CAAS;QACnB,WAAM,GAAN,MAAM,CAA4B;IAC1C,CAAC;IAEJ,CAAC,IAAI;QACH,IAAI,IAAI,CAAC,MAAM;YAAE,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC5C,CAAC;IAED,SAAS,CAAC,GAAW;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG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nE,CACF,CAAA;AAED;;GAEG;AACH,SAAS,qBAAqB,CAAC,KAAa;IAC1C,2EAA2E;IAC3E,oCAAoC;IACpC,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;IAE1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,wDAAwD;QACxD,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,4DAA4D;YAC5D,6CAA6C;YAC7C,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;YAEzC,6DAA6D;YAC7D,MAAM,cAAc,GAAG,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;YAC9D,IAAI,cAAc,EAAE,CAAC;gBACnB,4DAA4D;gBAC5D,KAAK,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EAAE,CAAA;gBAErF,gDAAgD;gBAChD,CAAC,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,CAAA;gBAE9B,uEAAuE;gBACvE,GAAG,IAAI,WAAW,CAAC,MAAM,GAAG,cAAc,CAAC,MAAM,CAAA;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { ScopeStringFor, ScopeSyntax } from './syntax.js'\nimport { minIdx } from './util.js'\n\n/**\n * Translates a scope string into a {@link ScopeSyntax}.\n */\nexport class ScopeStringSyntax<P extends string> implements ScopeSyntax<P> {\n constructor(\n readonly prefix: P,\n readonly positional?: string,\n readonly params?: Readonly<URLSearchParams>,\n ) {}\n\n *keys() {\n if (this.params) yield* this.params.keys()\n }\n\n getSingle(key: string) {\n if (!this.params?.has(key)) return undefined\n const value = this.params.getAll(key)\n if (value.length > 1) return null\n return value[0]!\n }\n\n getMulti(key: string) {\n if (!this.params?.has(key)) return undefined\n return this.params.getAll(key)\n }\n\n toString() {\n let scope: string = this.prefix\n\n if (this.positional !== undefined) {\n scope += `:${normalizeURIComponent(encodeURIComponent(this.positional))}`\n }\n\n if (this.params?.size) {\n scope += `?${normalizeURIComponent(this.params.toString())}`\n }\n\n return scope as ScopeStringFor<P>\n }\n\n static fromString<P extends string>(\n scopeValue: ScopeStringFor<P>,\n ): ScopeStringSyntax<P> {\n const paramIdx = scopeValue.indexOf('?')\n const colonIdx = scopeValue.indexOf(':')\n const prefixEnd = minIdx(paramIdx, colonIdx)\n\n // No param or positional\n if (prefixEnd === -1) {\n return new ScopeStringSyntax(scopeValue as P)\n }\n\n const prefix = scopeValue.slice(0, prefixEnd) as P\n\n // Parse the positional parameter if present\n const positional =\n colonIdx !== -1\n ? paramIdx === -1\n ? decodeURIComponent(scopeValue.slice(colonIdx + 1))\n : colonIdx < paramIdx\n ? decodeURIComponent(scopeValue.slice(colonIdx + 1, paramIdx))\n : undefined\n : undefined\n\n // Parse the query string if present and non empty\n const params =\n paramIdx !== -1 && paramIdx < scopeValue.length - 1\n ? new URLSearchParams(scopeValue.slice(paramIdx + 1))\n : undefined\n\n return new ScopeStringSyntax(prefix, positional, params)\n }\n}\n\n/**\n * Set of characters that are allowed in scope components without encoding. This\n * is used to normalize scope components.\n */\nconst ALLOWED_SCOPE_CHARS = new Set(\n // @NOTE This list must not contain \"?\" or \"&\" as it would interfere with\n // query string parsing.\n [':', '/', '+', ',', '@', '%'],\n)\n\nconst NORMALIZABLE_CHARS_MAP = new Map(\n Array.from(\n ALLOWED_SCOPE_CHARS,\n (c) => [encodeURIComponent(c), c] as const,\n ).filter(\n ([encoded, c]) =>\n // Make sure that any char added to ALLOWED_SCOPE_CHARS that is a char\n // that indeed needs encoding. Also, the normalizeURIComponent only\n // supports three-character percent-encoded sequences.\n encoded !== c && encoded.length === 3 && encoded.startsWith('%'),\n ),\n)\n\n/**\n * Assumes a properly url-encoded string.\n */\nfunction normalizeURIComponent(value: string): string {\n // No need to read the last two characters since percent encoded characters\n // are always three characters long.\n let end = value.length - 2\n\n for (let i = 0; i < end; i++) {\n // Check if the character is a percent-encoded character\n if (value.charCodeAt(i) === 0x25 /* % */) {\n // Read the next encoded char. Current version only supports\n // three-character percent-encoded sequences.\n const encodedChar = value.slice(i, i + 3)\n\n // Check if the encoded character is in the normalization map\n const normalizedChar = NORMALIZABLE_CHARS_MAP.get(encodedChar)\n if (normalizedChar) {\n // Replace the encoded character with its normalized version\n value = `${value.slice(0, i)}${normalizedChar}${value.slice(i + encodedChar.length)}`\n\n // Adjust index to account for the length change\n i += normalizedChar.length - 1\n\n // Adjust end index since we replaced encoded char with normalized char\n end -= encodedChar.length - normalizedChar.length\n }\n }\n }\n\n return value\n}\n"]}
|
package/dist/lib/syntax.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isScopeStringFor = isScopeStringFor;
|
|
4
|
-
exports.isScopeSyntaxFor = isScopeSyntaxFor;
|
|
5
1
|
/**
|
|
6
2
|
* Allows to quickly check if a scope is for a specific resource.
|
|
7
3
|
*/
|
|
8
|
-
function isScopeStringFor(value, prefix) {
|
|
4
|
+
export function isScopeStringFor(value, prefix) {
|
|
9
5
|
if (value.length > prefix.length) {
|
|
10
6
|
// First, check the next char is either : or ?
|
|
11
7
|
const nextChar = value.charCodeAt(prefix.length);
|
|
@@ -20,7 +16,7 @@ function isScopeStringFor(value, prefix) {
|
|
|
20
16
|
return value === prefix;
|
|
21
17
|
}
|
|
22
18
|
}
|
|
23
|
-
function isScopeSyntaxFor(syntax, prefix) {
|
|
19
|
+
export function isScopeSyntaxFor(syntax, prefix) {
|
|
24
20
|
return syntax.prefix === prefix;
|
|
25
21
|
}
|
|
26
22
|
//# sourceMappingURL=syntax.js.map
|
package/dist/lib/syntax.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../../src/lib/syntax.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../../src/lib/syntax.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,MAAS;IAET,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACjC,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAChD,IAAI,QAAQ,KAAK,IAAI,CAAC,OAAO,IAAI,QAAQ,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3D,OAAO,KAAK,CAAA;QACd,CAAC;QAED,6BAA6B;QAC7B,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC;SAAM,CAAC;QACN,iCAAiC;QACjC,OAAO,KAAK,KAAK,MAAM,CAAA;IACzB,CAAC;AACH,CAAC;AAcD,MAAM,UAAU,gBAAgB,CAC9B,MAA2B,EAC3B,MAAS;IAET,OAAO,MAAM,CAAC,MAAM,KAAK,MAAM,CAAA;AACjC,CAAC","sourcesContent":["export type ParamValue = string | number | boolean\n\nexport type NeArray<T> = [T, ...T[]]\n\n/**\n * Non-empty readonly array\n */\nexport type NeRoArray<T> = readonly [T, ...T[]]\n\nexport type ScopeStringFor<P extends string> =\n | P\n | `${P}:${string}`\n | `${P}?${string}`\n\n/**\n * Allows to quickly check if a scope is for a specific resource.\n */\nexport function isScopeStringFor<P extends string>(\n value: string,\n prefix: P,\n): value is ScopeStringFor<P> {\n if (value.length > prefix.length) {\n // First, check the next char is either : or ?\n const nextChar = value.charCodeAt(prefix.length)\n if (nextChar !== 0x3a /* : */ && nextChar !== 0x3f /* ? */) {\n return false\n }\n\n // Then check the full prefix\n return value.startsWith(prefix)\n } else {\n // value and prefix must be equal\n return value === prefix\n }\n}\n\n/**\n * Abstract interface that allows parsing various syntaxes into permission\n * representations.\n */\nexport interface ScopeSyntax<P extends string> {\n readonly prefix: P\n readonly positional?: ParamValue\n keys(): Iterable<string, void, unknown>\n getSingle(key: string): ParamValue | null | undefined\n getMulti(key: string): readonly ParamValue[] | null | undefined\n}\n\nexport function isScopeSyntaxFor<P extends string>(\n syntax: ScopeSyntax<string>,\n prefix: P,\n): syntax is ScopeSyntax<P> {\n return syntax.prefix === prefix\n}\n"]}
|
package/dist/lib/util.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.minIdx = minIdx;
|
|
4
|
-
exports.knownValuesValidator = knownValuesValidator;
|
|
5
|
-
exports.isNonNullable = isNonNullable;
|
|
6
|
-
function minIdx(a, b) {
|
|
1
|
+
export function minIdx(a, b) {
|
|
7
2
|
if (a === -1)
|
|
8
3
|
return b;
|
|
9
4
|
if (b === -1)
|
|
10
5
|
return a;
|
|
11
6
|
return Math.min(a, b);
|
|
12
7
|
}
|
|
13
|
-
function knownValuesValidator(values) {
|
|
8
|
+
export function knownValuesValidator(values) {
|
|
14
9
|
const set = new Set(values);
|
|
15
10
|
return (value) => set.has(value);
|
|
16
11
|
}
|
|
17
|
-
function isNonNullable(value) {
|
|
12
|
+
export function isNonNullable(value) {
|
|
18
13
|
return value != null;
|
|
19
14
|
}
|
|
20
15
|
//# sourceMappingURL=util.js.map
|
package/dist/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,IAAI,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,CAAA;IACtB,IAAI,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,CAAA;IACtB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAI,MAAmB;IACzD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAU,MAAM,CAAC,CAAA;IACpC,OAAO,CAAC,KAAc,EAAc,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACvD,CAAC;AAED,MAAM,UAAU,aAAa,CAAI,KAAQ;IACvC,OAAO,KAAK,IAAI,IAAI,CAAA;AACtB,CAAC","sourcesContent":["export interface Matchable<T> {\n matches(options: T): boolean\n}\n\nexport function minIdx(a: number, b: number): number {\n if (a === -1) return b\n if (b === -1) return a\n return Math.min(a, b)\n}\n\nexport function knownValuesValidator<T>(values: Iterable<T>) {\n const set = new Set<unknown>(values)\n return (value: unknown): value is T => set.has(value)\n}\n\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value != null\n}\n"]}
|