@atproto/oauth-scopes 0.0.1

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE.txt +7 -0
  3. package/dist/index.d.ts +16 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +32 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/did.d.ts +3 -0
  8. package/dist/lib/did.d.ts.map +1 -0
  9. package/dist/lib/did.js +6 -0
  10. package/dist/lib/did.js.map +1 -0
  11. package/dist/lib/mime.d.ts +7 -0
  12. package/dist/lib/mime.d.ts.map +1 -0
  13. package/dist/lib/mime.js +65 -0
  14. package/dist/lib/mime.js.map +1 -0
  15. package/dist/lib/nsid.d.ts +3 -0
  16. package/dist/lib/nsid.d.ts.map +1 -0
  17. package/dist/lib/nsid.js +9 -0
  18. package/dist/lib/nsid.js.map +1 -0
  19. package/dist/lib/util.d.ts +3 -0
  20. package/dist/lib/util.d.ts.map +1 -0
  21. package/dist/lib/util.js +24 -0
  22. package/dist/lib/util.js.map +1 -0
  23. package/dist/parser.d.ts +31 -0
  24. package/dist/parser.d.ts.map +1 -0
  25. package/dist/parser.js +118 -0
  26. package/dist/parser.js.map +1 -0
  27. package/dist/permission-set-transition.d.ts +15 -0
  28. package/dist/permission-set-transition.d.ts.map +1 -0
  29. package/dist/permission-set-transition.js +52 -0
  30. package/dist/permission-set-transition.js.map +1 -0
  31. package/dist/permission-set.d.ts +22 -0
  32. package/dist/permission-set.d.ts.map +1 -0
  33. package/dist/permission-set.js +68 -0
  34. package/dist/permission-set.js.map +1 -0
  35. package/dist/resources/account-scope.d.ts +35 -0
  36. package/dist/resources/account-scope.d.ts.map +1 -0
  37. package/dist/resources/account-scope.js +60 -0
  38. package/dist/resources/account-scope.js.map +1 -0
  39. package/dist/resources/blob-scope.d.ts +25 -0
  40. package/dist/resources/blob-scope.d.ts.map +1 -0
  41. package/dist/resources/blob-scope.js +74 -0
  42. package/dist/resources/blob-scope.js.map +1 -0
  43. package/dist/resources/identity-scope.d.ts +25 -0
  44. package/dist/resources/identity-scope.d.ts.map +1 -0
  45. package/dist/resources/identity-scope.js +46 -0
  46. package/dist/resources/identity-scope.js.map +1 -0
  47. package/dist/resources/repo-scope.d.ts +37 -0
  48. package/dist/resources/repo-scope.d.ts.map +1 -0
  49. package/dist/resources/repo-scope.js +92 -0
  50. package/dist/resources/repo-scope.js.map +1 -0
  51. package/dist/resources/rpc-scope.d.ts +31 -0
  52. package/dist/resources/rpc-scope.d.ts.map +1 -0
  53. package/dist/resources/rpc-scope.js +74 -0
  54. package/dist/resources/rpc-scope.js.map +1 -0
  55. package/dist/scope-missing-error.d.ts +9 -0
  56. package/dist/scope-missing-error.d.ts.map +1 -0
  57. package/dist/scope-missing-error.js +39 -0
  58. package/dist/scope-missing-error.js.map +1 -0
  59. package/dist/scopes-set.d.ts +21 -0
  60. package/dist/scopes-set.d.ts.map +1 -0
  61. package/dist/scopes-set.js +55 -0
  62. package/dist/scopes-set.js.map +1 -0
  63. package/dist/syntax.d.ts +76 -0
  64. package/dist/syntax.d.ts.map +1 -0
  65. package/dist/syntax.js +249 -0
  66. package/dist/syntax.js.map +1 -0
  67. package/dist/utilities.d.ts +17 -0
  68. package/dist/utilities.d.ts.map +1 -0
  69. package/dist/utilities.js +108 -0
  70. package/dist/utilities.js.map +1 -0
  71. package/jest.config.js +5 -0
  72. package/package.json +36 -0
  73. package/src/index.ts +17 -0
  74. package/src/lib/did.ts +3 -0
  75. package/src/lib/mime.test.ts +98 -0
  76. package/src/lib/mime.ts +70 -0
  77. package/src/lib/nsid.ts +6 -0
  78. package/src/lib/util.ts +19 -0
  79. package/src/parser.ts +150 -0
  80. package/src/permission-set-transition.test.ts +109 -0
  81. package/src/permission-set-transition.ts +67 -0
  82. package/src/permission-set.test.ts +225 -0
  83. package/src/permission-set.ts +78 -0
  84. package/src/resources/account-scope.test.ts +175 -0
  85. package/src/resources/account-scope.ts +66 -0
  86. package/src/resources/blob-scope.test.ts +118 -0
  87. package/src/resources/blob-scope.ts +86 -0
  88. package/src/resources/identity-scope.test.ts +80 -0
  89. package/src/resources/identity-scope.ts +49 -0
  90. package/src/resources/repo-scope.test.ts +255 -0
  91. package/src/resources/repo-scope.ts +101 -0
  92. package/src/resources/rpc-scope.test.ts +280 -0
  93. package/src/resources/rpc-scope.ts +77 -0
  94. package/src/scope-missing-error.ts +15 -0
  95. package/src/scopes-set.test.ts +47 -0
  96. package/src/scopes-set.ts +60 -0
  97. package/src/syntax.test.ts +203 -0
  98. package/src/syntax.ts +325 -0
  99. package/src/utilities.ts +109 -0
  100. package/tsconfig.build.json +9 -0
  101. package/tsconfig.build.tsbuildinfo +1 -0
  102. package/tsconfig.json +7 -0
  103. package/tsconfig.tests.json +7 -0
  104. package/tsconfig.tests.tsbuildinfo +1 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccountScope = exports.accountParser = void 0;
4
+ const parser_js_1 = require("../parser.js");
5
+ const syntax_js_1 = require("../syntax.js");
6
+ const ACCOUNT_ATTRIBUTES = Object.freeze(['email', 'repo', 'status']);
7
+ const ACCOUNT_ACTIONS = Object.freeze(['read', 'manage']);
8
+ exports.accountParser = new parser_js_1.Parser('account', {
9
+ attr: {
10
+ multiple: false,
11
+ required: true,
12
+ validate: (0, parser_js_1.knownValuesValidator)(ACCOUNT_ATTRIBUTES),
13
+ },
14
+ action: {
15
+ multiple: false,
16
+ required: false,
17
+ validate: (0, parser_js_1.knownValuesValidator)(ACCOUNT_ACTIONS),
18
+ default: 'read',
19
+ },
20
+ }, 'attr');
21
+ class AccountScope {
22
+ constructor(attr, action) {
23
+ Object.defineProperty(this, "attr", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: attr
28
+ });
29
+ Object.defineProperty(this, "action", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: action
34
+ });
35
+ }
36
+ matches(options) {
37
+ return (this.attr === options.attr &&
38
+ (this.action === 'manage' || this.action === options.action));
39
+ }
40
+ toString() {
41
+ return exports.accountParser.format(this);
42
+ }
43
+ static fromString(scope) {
44
+ if (!(0, syntax_js_1.isScopeForResource)(scope, 'account'))
45
+ return null;
46
+ const syntax = syntax_js_1.ResourceSyntax.fromString(scope);
47
+ return this.fromSyntax(syntax);
48
+ }
49
+ static fromSyntax(syntax) {
50
+ const result = exports.accountParser.parse(syntax);
51
+ if (!result)
52
+ return null;
53
+ return new AccountScope(result.attr, result.action);
54
+ }
55
+ static scopeNeededFor(options) {
56
+ return exports.accountParser.format(options);
57
+ }
58
+ }
59
+ exports.AccountScope = AccountScope;
60
+ //# sourceMappingURL=account-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-scope.js","sourceRoot":"","sources":["../../src/resources/account-scope.ts"],"names":[],"mappings":";;;AAAA,4CAA2D;AAC3D,4CAAiE;AAEjE,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC,CAAA;AAG9E,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAU,CAAC,CAAA;AAGrD,QAAA,aAAa,GAAG,IAAI,kBAAM,CACrC,SAAS,EACT;IACE,IAAI,EAAE;QACJ,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAA,gCAAoB,EAAC,kBAAkB,CAAC;KACnD;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,IAAA,gCAAoB,EAAC,eAAe,CAAC;QAC/C,OAAO,EAAE,MAAe;KACzB;CACF,EACD,MAAM,CACP,CAAA;AAOD,MAAa,YAAY;IACvB,YACkB,IAAsB,EACtB,MAAqB;QADrC;;;;mBAAgB,IAAI;WAAkB;QACtC;;;;mBAAgB,MAAM;WAAe;IACpC,CAAC;IAEJ,OAAO,CAAC,OAA0B;QAChC,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI;YAC1B,CAAC,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAC7D,CAAA;IACH,CAAC;IAED,QAAQ;QACN,OAAO,qBAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,CAAC,IAAA,8BAAkB,EAAC,KAAK,EAAE,SAAS,CAAC;YAAE,OAAO,IAAI,CAAA;QACtD,MAAM,MAAM,GAAG,0BAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAsB;QACtC,MAAM,MAAM,GAAG,qBAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IACrD,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAA0B;QAC9C,OAAO,qBAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACtC,CAAC;CACF;AAjCD,oCAiCC"}
@@ -0,0 +1,25 @@
1
+ import { Accept, isAccept } from '../lib/mime.js';
2
+ import { Parser } from '../parser.js';
3
+ import { NeRoArray, ResourceSyntax } from '../syntax.js';
4
+ export declare const DEFAULT_ACCEPT: readonly ["*/*"];
5
+ export declare const blobParser: Parser<"blob", {
6
+ accept: {
7
+ multiple: true;
8
+ required: true;
9
+ validate: typeof isAccept;
10
+ normalize: (value: NeRoArray<string>) => readonly ["*/*"] | [Accept, ...Accept[]];
11
+ };
12
+ }>;
13
+ export type BlobScopeMatch = {
14
+ mime: string;
15
+ };
16
+ export declare class BlobScope {
17
+ readonly accept: NeRoArray<Accept>;
18
+ constructor(accept: NeRoArray<Accept>);
19
+ matches(options: BlobScopeMatch): boolean;
20
+ toString(): import("../syntax.js").ScopeForResource<"blob">;
21
+ static fromString(scope: string): BlobScope | null;
22
+ static fromSyntax(syntax: ResourceSyntax): BlobScope | null;
23
+ static scopeNeededFor(options: BlobScopeMatch): import("../syntax.js").ScopeForResource<"blob">;
24
+ }
25
+ //# sourceMappingURL=blob-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob-scope.d.ts","sourceRoot":"","sources":["../../src/resources/blob-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAoB,MAAM,gBAAgB,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAsB,MAAM,cAAc,CAAA;AAE5E,eAAO,MAAM,cAAc,kBAAkC,CAAA;AAE7D,eAAO,MAAM,UAAU;;;;;;;EAmBtB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,qBAAa,SAAS;aACQ,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;gBAAzB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;IAErD,OAAO,CAAC,OAAO,EAAE,cAAc;IAI/B,QAAQ;IAIR,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM;IAM/B,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc;IAOxC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc;CAK9C"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlobScope = exports.blobParser = exports.DEFAULT_ACCEPT = void 0;
4
+ const mime_js_1 = require("../lib/mime.js");
5
+ const parser_js_1 = require("../parser.js");
6
+ const syntax_js_1 = require("../syntax.js");
7
+ exports.DEFAULT_ACCEPT = Object.freeze(['*/*']);
8
+ exports.blobParser = new parser_js_1.Parser('blob', {
9
+ accept: {
10
+ multiple: true,
11
+ required: true,
12
+ validate: mime_js_1.isAccept,
13
+ normalize: (value) => {
14
+ // Returns a more concise representation of the accept values.
15
+ if (value.includes('*/*'))
16
+ return exports.DEFAULT_ACCEPT;
17
+ return value.map(toLowerCase).filter(isNonRedundant);
18
+ },
19
+ },
20
+ }, 'accept');
21
+ class BlobScope {
22
+ constructor(accept) {
23
+ Object.defineProperty(this, "accept", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: accept
28
+ });
29
+ }
30
+ matches(options) {
31
+ return (0, mime_js_1.matchesAnyAccept)(this.accept, options.mime);
32
+ }
33
+ toString() {
34
+ return exports.blobParser.format(this);
35
+ }
36
+ static fromString(scope) {
37
+ if (!(0, syntax_js_1.isScopeForResource)(scope, 'blob'))
38
+ return null;
39
+ const syntax = syntax_js_1.ResourceSyntax.fromString(scope);
40
+ return this.fromSyntax(syntax);
41
+ }
42
+ static fromSyntax(syntax) {
43
+ const result = exports.blobParser.parse(syntax);
44
+ if (!result)
45
+ return null;
46
+ return new BlobScope(result.accept);
47
+ }
48
+ static scopeNeededFor(options) {
49
+ return exports.blobParser.format({
50
+ accept: [options.mime],
51
+ });
52
+ }
53
+ }
54
+ exports.BlobScope = BlobScope;
55
+ function toLowerCase(value) {
56
+ return value.toLowerCase();
57
+ }
58
+ function isNonRedundant(value, index, arr) {
59
+ if (value.endsWith('/*')) {
60
+ // assuming the array contains unique element, wildcards cannot be redundant
61
+ // with one another ('image/*' is not redundant with 'text/*')
62
+ return true;
63
+ }
64
+ const base = value.split('/', 1)[0];
65
+ if (arr.includes(`${base}/*`)) {
66
+ // If another value in the array is a wildcard for the same base, we can
67
+ // skip this one as it is redundant. e.g. if the array contains 'image/png'
68
+ // and 'image/*', we can skip 'image/png' because 'image/*' already covers
69
+ // it.
70
+ return false;
71
+ }
72
+ return true;
73
+ }
74
+ //# sourceMappingURL=blob-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob-scope.js","sourceRoot":"","sources":["../../src/resources/blob-scope.ts"],"names":[],"mappings":";;;AAAA,4CAAmE;AACnE,4CAAqC;AACrC,4CAA4E;AAE/D,QAAA,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAU,CAAC,CAAA;AAEhD,QAAA,UAAU,GAAG,IAAI,kBAAM,CAClC,MAAM,EACN;IACE,MAAM,EAAE;QACN,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,kBAAQ;QAClB,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,8DAA8D;YAC9D,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,OAAO,sBAAc,CAAA;YAEhD,OAAO,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,cAAc,CAGlD,CAAA;QACH,CAAC;KACF;CACF,EACD,QAAQ,CACT,CAAA;AAMD,MAAa,SAAS;IACpB,YAA4B,MAAyB;QAAzC;;;;mBAAgB,MAAM;WAAmB;IAAG,CAAC;IAEzD,OAAO,CAAC,OAAuB;QAC7B,OAAO,IAAA,0BAAgB,EAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAED,QAAQ;QACN,OAAO,kBAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,CAAC,IAAA,8BAAkB,EAAC,KAAK,EAAE,MAAM,CAAC;YAAE,OAAO,IAAI,CAAA;QACnD,MAAM,MAAM,GAAG,0BAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAsB;QACtC,MAAM,MAAM,GAAG,kBAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACvC,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAAuB;QAC3C,OAAO,kBAAU,CAAC,MAAM,CAAC;YACvB,MAAM,EAAE,CAAC,OAAO,CAAC,IAAc,CAAC;SACjC,CAAC,CAAA;IACJ,CAAC;CACF;AA7BD,8BA6BC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;AAC5B,CAAC;AAED,SAAS,cAAc,CACrB,KAAa,EACb,KAAa,EACb,GAAsB;IAEtB,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,4EAA4E;QAC5E,8DAA8D;QAC9D,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;QAC9B,wEAAwE;QACxE,2EAA2E;QAC3E,0EAA0E;QAC1E,MAAM;QACN,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { Parser } from '../parser.js';
2
+ import { ResourceSyntax } from '../syntax.js';
3
+ declare const IDENTITY_ATTRIBUTES: readonly ["handle", "*"];
4
+ export type IdentityAttribute = (typeof IDENTITY_ATTRIBUTES)[number];
5
+ export declare const identityParser: Parser<"identity", {
6
+ attr: {
7
+ multiple: false;
8
+ required: true;
9
+ validate: (value: string) => value is "*" | "handle";
10
+ };
11
+ }>;
12
+ export type IdentityScopeMatch = {
13
+ attr: IdentityAttribute;
14
+ };
15
+ export declare class IdentityScope {
16
+ readonly attr: IdentityAttribute;
17
+ constructor(attr: IdentityAttribute);
18
+ matches(options: IdentityScopeMatch): boolean;
19
+ toString(): import("../syntax.js").ScopeForResource<"identity">;
20
+ static fromString(scope: string): IdentityScope | null;
21
+ static fromSyntax(syntax: ResourceSyntax): IdentityScope | null;
22
+ static scopeNeededFor(options: IdentityScopeMatch): string;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=identity-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-scope.d.ts","sourceRoot":"","sources":["../../src/resources/identity-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwB,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAsB,MAAM,cAAc,CAAA;AAEjE,QAAA,MAAM,mBAAmB,0BAA0C,CAAA;AACnE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEpE,eAAO,MAAM,cAAc;;;;;;EAU1B,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,iBAAiB,CAAA;CACxB,CAAA;AAED,qBAAa,aAAa;aACI,IAAI,EAAE,iBAAiB;gBAAvB,IAAI,EAAE,iBAAiB;IAEnD,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO;IAI7C,QAAQ;IAIR,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM;IAM/B,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc;IAMxC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM;CAG3D"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IdentityScope = exports.identityParser = void 0;
4
+ const parser_js_1 = require("../parser.js");
5
+ const syntax_js_1 = require("../syntax.js");
6
+ const IDENTITY_ATTRIBUTES = Object.freeze(['handle', '*']);
7
+ exports.identityParser = new parser_js_1.Parser('identity', {
8
+ attr: {
9
+ multiple: false,
10
+ required: true,
11
+ validate: (0, parser_js_1.knownValuesValidator)(IDENTITY_ATTRIBUTES),
12
+ },
13
+ }, 'attr');
14
+ class IdentityScope {
15
+ constructor(attr) {
16
+ Object.defineProperty(this, "attr", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: attr
21
+ });
22
+ }
23
+ matches(options) {
24
+ return this.attr === '*' || this.attr === options.attr;
25
+ }
26
+ toString() {
27
+ return exports.identityParser.format(this);
28
+ }
29
+ static fromString(scope) {
30
+ if (!(0, syntax_js_1.isScopeForResource)(scope, 'identity'))
31
+ return null;
32
+ const syntax = syntax_js_1.ResourceSyntax.fromString(scope);
33
+ return this.fromSyntax(syntax);
34
+ }
35
+ static fromSyntax(syntax) {
36
+ const result = exports.identityParser.parse(syntax);
37
+ if (!result)
38
+ return null;
39
+ return new IdentityScope(result.attr);
40
+ }
41
+ static scopeNeededFor(options) {
42
+ return exports.identityParser.format(options);
43
+ }
44
+ }
45
+ exports.IdentityScope = IdentityScope;
46
+ //# sourceMappingURL=identity-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-scope.js","sourceRoot":"","sources":["../../src/resources/identity-scope.ts"],"names":[],"mappings":";;;AAAA,4CAA2D;AAC3D,4CAAiE;AAEjE,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAU,CAAC,CAAA;AAGtD,QAAA,cAAc,GAAG,IAAI,kBAAM,CACtC,UAAU,EACV;IACE,IAAI,EAAE;QACJ,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAA,gCAAoB,EAAC,mBAAmB,CAAC;KACpD;CACF,EACD,MAAM,CACP,CAAA;AAMD,MAAa,aAAa;IACxB,YAA4B,IAAuB;QAAvC;;;;mBAAgB,IAAI;WAAmB;IAAG,CAAC;IAEvD,OAAO,CAAC,OAA2B;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAA;IACxD,CAAC;IAED,QAAQ;QACN,OAAO,sBAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,CAAC,IAAA,8BAAkB,EAAC,KAAK,EAAE,UAAU,CAAC;YAAE,OAAO,IAAI,CAAA;QACvD,MAAM,MAAM,GAAG,0BAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAsB;QACtC,MAAM,MAAM,GAAG,sBAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC3C,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QACxB,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAA2B;QAC/C,OAAO,sBAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;CACF;AA1BD,sCA0BC"}
@@ -0,0 +1,37 @@
1
+ import { NSID } from '../lib/nsid.js';
2
+ import { Parser } from '../parser.js';
3
+ import { NeRoArray, ResourceSyntax } from '../syntax.js';
4
+ declare const REPO_ACTIONS: readonly ["create", "update", "delete"];
5
+ export type RepoAction = (typeof REPO_ACTIONS)[number];
6
+ export declare const isRepoAction: (value: string) => value is "delete" | "create" | "update";
7
+ export declare const repoParser: Parser<"repo", {
8
+ collection: {
9
+ multiple: true;
10
+ required: true;
11
+ validate: (value: string) => value is "*" | `${string}.${string}`;
12
+ normalize: (value: NeRoArray<string>) => NeRoArray<string>;
13
+ };
14
+ action: {
15
+ multiple: true;
16
+ required: false;
17
+ validate: (value: string) => value is "delete" | "create" | "update";
18
+ default: readonly ["create", "update", "delete"];
19
+ };
20
+ }>;
21
+ export type RepoScopeMatch = {
22
+ collection: string;
23
+ action: RepoAction;
24
+ };
25
+ export declare class RepoScope {
26
+ readonly collection: NeRoArray<'*' | NSID>;
27
+ readonly action: NeRoArray<RepoAction>;
28
+ constructor(collection: NeRoArray<'*' | NSID>, action: NeRoArray<RepoAction>);
29
+ get allowsAnyCollection(): boolean;
30
+ matches({ action, collection }: RepoScopeMatch): boolean;
31
+ toString(): string;
32
+ static fromString(scope: string): RepoScope | null;
33
+ static fromSyntax(syntax: ResourceSyntax): RepoScope | null;
34
+ static scopeNeededFor(options: RepoScopeMatch): string;
35
+ }
36
+ export {};
37
+ //# sourceMappingURL=repo-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-scope.d.ts","sourceRoot":"","sources":["../../src/resources/repo-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAU,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAwB,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAsB,MAAM,cAAc,CAAA;AAE5E,QAAA,MAAM,YAAY,yCAAyD,CAAA;AAC3E,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AACtD,eAAO,MAAM,YAAY,4DAAqC,CAAA;AAE9D,eAAO,MAAM,UAAU;;;;;;;;;;;;;EAoBtB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,qBAAa,SAAS;aAEF,UAAU,EAAE,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC;aACjC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC;gBAD7B,UAAU,EAAE,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC,EACjC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC;IAG/C,IAAI,mBAAmB,YAEtB;IAED,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,cAAc,GAAG,OAAO;IAQxD,QAAQ,IAAI,MAAM;IAkBlB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAMlD,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI;IAO3D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM;CAMvD"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RepoScope = exports.repoParser = exports.isRepoAction = void 0;
4
+ const nsid_js_1 = require("../lib/nsid.js");
5
+ const parser_js_1 = require("../parser.js");
6
+ const syntax_js_1 = require("../syntax.js");
7
+ const REPO_ACTIONS = Object.freeze(['create', 'update', 'delete']);
8
+ exports.isRepoAction = (0, parser_js_1.knownValuesValidator)(REPO_ACTIONS);
9
+ exports.repoParser = new parser_js_1.Parser('repo', {
10
+ collection: {
11
+ multiple: true,
12
+ required: true,
13
+ validate: (value) => value === '*' || (0, nsid_js_1.isNSID)(value),
14
+ normalize: (value) => {
15
+ if (value.length > 1 && value.includes('*'))
16
+ return ['*'];
17
+ return value;
18
+ },
19
+ },
20
+ action: {
21
+ multiple: true,
22
+ required: false,
23
+ validate: exports.isRepoAction,
24
+ default: REPO_ACTIONS,
25
+ },
26
+ }, 'collection');
27
+ class RepoScope {
28
+ constructor(collection, action) {
29
+ Object.defineProperty(this, "collection", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: collection
34
+ });
35
+ Object.defineProperty(this, "action", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: action
40
+ });
41
+ }
42
+ get allowsAnyCollection() {
43
+ return this.collection.includes('*');
44
+ }
45
+ matches({ action, collection }) {
46
+ return (this.action.includes(action) &&
47
+ (this.allowsAnyCollection ||
48
+ this.collection.includes(collection)));
49
+ }
50
+ toString() {
51
+ // Normalize (compress, de-dupe, sort)
52
+ return exports.repoParser.format({
53
+ collection: this.allowsAnyCollection
54
+ ? ['*']
55
+ : this.collection.length > 1
56
+ ? [...new Set(this.collection)].sort()
57
+ : this.collection,
58
+ action: this.action === REPO_ACTIONS
59
+ ? REPO_ACTIONS // No need to filter if the default was used
60
+ : REPO_ACTIONS.filter(includedIn, this.action),
61
+ });
62
+ }
63
+ static fromString(scope) {
64
+ if (!(0, syntax_js_1.isScopeForResource)(scope, 'repo'))
65
+ return null;
66
+ const syntax = syntax_js_1.ResourceSyntax.fromString(scope);
67
+ return this.fromSyntax(syntax);
68
+ }
69
+ static fromSyntax(syntax) {
70
+ const result = exports.repoParser.parse(syntax);
71
+ if (!result)
72
+ return null;
73
+ return new RepoScope(result.collection, result.action);
74
+ }
75
+ static scopeNeededFor(options) {
76
+ return exports.repoParser.format({
77
+ collection: [options.collection],
78
+ action: [options.action],
79
+ });
80
+ }
81
+ }
82
+ exports.RepoScope = RepoScope;
83
+ /**
84
+ * Special utility function to be used as predicate for array methods like
85
+ * `Array.prototype.includes`, etc. When used as predicate, it expects that
86
+ * the array method is called with a `thisArg` that is a readonly array of
87
+ * the same type as the `value` parameter.
88
+ */
89
+ function includedIn(value) {
90
+ return this.includes(value);
91
+ }
92
+ //# sourceMappingURL=repo-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-scope.js","sourceRoot":"","sources":["../../src/resources/repo-scope.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAC7C,4CAA2D;AAC3D,4CAA4E;AAE5E,MAAM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;AAED;;;;;GAKG;AACH,SAAS,UAAU,CAAwB,KAAQ;IACjD,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { DIDLike } from '../lib/did.js';
2
+ import { NSID } from '../lib/nsid.js';
3
+ import { Parser } from '../parser.js';
4
+ import { NeRoArray, ResourceSyntax } from '../syntax.js';
5
+ export declare const rpcParser: Parser<"rpc", {
6
+ lxm: {
7
+ multiple: true;
8
+ required: true;
9
+ validate: (value: string) => value is "*" | `${string}.${string}`;
10
+ };
11
+ aud: {
12
+ multiple: false;
13
+ required: true;
14
+ validate: (value: string) => value is "*" | `did:${string}`;
15
+ };
16
+ }>;
17
+ export type RpcScopeMatch = {
18
+ lxm: string;
19
+ aud: string;
20
+ };
21
+ export declare class RpcScope {
22
+ readonly aud: '*' | DIDLike;
23
+ readonly lxm: NeRoArray<'*' | NSID>;
24
+ constructor(aud: '*' | DIDLike, lxm: NeRoArray<'*' | NSID>);
25
+ matches(options: RpcScopeMatch): boolean;
26
+ toString(): string;
27
+ static fromString(scope: string): RpcScope | null;
28
+ static fromSyntax(syntax: ResourceSyntax): RpcScope | null;
29
+ static scopeNeededFor(options: RpcScopeMatch): string;
30
+ }
31
+ //# sourceMappingURL=rpc-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-scope.d.ts","sourceRoot":"","sources":["../../src/resources/rpc-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAa,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,IAAI,EAAU,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAsB,MAAM,cAAc,CAAA;AAK5E,eAAO,MAAM,SAAS;;;;0BAHW,MAAM;;;;;0BACN,MAAM;;EAiBtC,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,qBAAa,QAAQ;aAED,GAAG,EAAE,GAAG,GAAG,OAAO;aAClB,GAAG,EAAE,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC;gBAD1B,GAAG,EAAE,GAAG,GAAG,OAAO,EAClB,GAAG,EAAE,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC;IAG5C,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;IAQxC,QAAQ,IAAI,MAAM;IAUlB,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI;IAMjD,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,GAAG,IAAI;IAU1D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM;CAMtD"}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RpcScope = exports.rpcParser = void 0;
4
+ const did_js_1 = require("../lib/did.js");
5
+ const nsid_js_1 = require("../lib/nsid.js");
6
+ const parser_js_1 = require("../parser.js");
7
+ const syntax_js_1 = require("../syntax.js");
8
+ const validateLxmParam = (value) => value === '*' || (0, nsid_js_1.isNSID)(value);
9
+ const validateAudParam = (value) => value === '*' || (0, did_js_1.isDIDLike)(value);
10
+ exports.rpcParser = new parser_js_1.Parser('rpc', {
11
+ lxm: {
12
+ multiple: true,
13
+ required: true,
14
+ validate: validateLxmParam,
15
+ },
16
+ aud: {
17
+ multiple: false,
18
+ required: true,
19
+ validate: validateAudParam,
20
+ },
21
+ }, 'lxm');
22
+ class RpcScope {
23
+ constructor(aud, lxm) {
24
+ Object.defineProperty(this, "aud", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: aud
29
+ });
30
+ Object.defineProperty(this, "lxm", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: lxm
35
+ });
36
+ }
37
+ matches(options) {
38
+ const { aud, lxm } = this;
39
+ return ((aud === '*' || aud === options.aud) &&
40
+ (lxm.includes('*') || lxm.includes(options.lxm)));
41
+ }
42
+ toString() {
43
+ const { lxm, aud } = this;
44
+ return exports.rpcParser.format({
45
+ aud,
46
+ lxm: lxm.includes('*')
47
+ ? ['*']
48
+ : [...new Set(lxm)].sort(),
49
+ });
50
+ }
51
+ static fromString(scope) {
52
+ if (!(0, syntax_js_1.isScopeForResource)(scope, 'rpc'))
53
+ return null;
54
+ const syntax = syntax_js_1.ResourceSyntax.fromString(scope);
55
+ return this.fromSyntax(syntax);
56
+ }
57
+ static fromSyntax(syntax) {
58
+ const result = exports.rpcParser.parse(syntax);
59
+ if (!result)
60
+ return null;
61
+ // rpc:*?aud=* is forbidden
62
+ if (result.aud === '*' && result.lxm.includes('*'))
63
+ return null;
64
+ return new RpcScope(result.aud, result.lxm);
65
+ }
66
+ static scopeNeededFor(options) {
67
+ return exports.rpcParser.format({
68
+ aud: options.aud,
69
+ lxm: [options.lxm],
70
+ });
71
+ }
72
+ }
73
+ exports.RpcScope = RpcScope;
74
+ //# sourceMappingURL=rpc-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-scope.js","sourceRoot":"","sources":["../../src/resources/rpc-scope.ts"],"names":[],"mappings":";;;AAAA,0CAAkD;AAClD,4CAA6C;AAC7C,4CAAqC;AACrC,4CAA4E;AAE5E,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,KAAK,GAAG,IAAI,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAA;AAC1E,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,KAAK,GAAG,IAAI,IAAA,kBAAS,EAAC,KAAK,CAAC,CAAA;AAEhE,QAAA,SAAS,GAAG,IAAI,kBAAM,CACjC,KAAK,EACL;IACE,GAAG,EAAE;QACH,QAAQ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AU,CAAC,MAAsB;QACtC,MAAM,MAAM,GAAG,iBAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACtC,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,2BAA2B;QAC3B,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAA;QAE/D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;IAC7C,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAAsB;QAC1C,OAAO,iBAAS,CAAC,MAAM,CAAC;YACtB,GAAG,EAAE,OAAO,CAAC,GAAc;YAC3B,GAAG,EAAE,CAAC,OAAO,CAAC,GAAW,CAAC;SAC3B,CAAC,CAAA;IACJ,CAAC;CACF;AA9CD,4BA8CC"}
@@ -0,0 +1,9 @@
1
+ export declare class ScopeMissingError extends Error {
2
+ readonly scope: string;
3
+ name: string;
4
+ status: number;
5
+ expose: boolean;
6
+ get statusCode(): number;
7
+ constructor(scope: string);
8
+ }
9
+ //# sourceMappingURL=scope-missing-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-missing-error.d.ts","sourceRoot":"","sources":["../src/scope-missing-error.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;aAWd,KAAK,EAAE,MAAM;IAVzC,IAAI,SAAsB;IAI1B,MAAM,SAAM;IACZ,MAAM,UAAO;IACb,IAAI,UAAU,WAEb;gBAE2B,KAAK,EAAE,MAAM;CAG1C"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScopeMissingError = void 0;
4
+ class ScopeMissingError extends Error {
5
+ get statusCode() {
6
+ return this.status;
7
+ }
8
+ constructor(scope) {
9
+ super(`Missing required scope "${scope}"`);
10
+ Object.defineProperty(this, "scope", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: scope
15
+ });
16
+ Object.defineProperty(this, "name", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: 'ScopeMissingError'
21
+ });
22
+ // compatibility layer with http-errors package. The goal if to make
23
+ // isHttpError(new ScopeMissingError) return true.
24
+ Object.defineProperty(this, "status", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: 403
29
+ });
30
+ Object.defineProperty(this, "expose", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: true
35
+ });
36
+ }
37
+ }
38
+ exports.ScopeMissingError = ScopeMissingError;
39
+ //# sourceMappingURL=scope-missing-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-missing-error.js","sourceRoot":"","sources":["../src/scope-missing-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAkB,SAAQ,KAAK;IAO1C,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,YAA4B,KAAa;QACvC,KAAK,CAAC,2BAA2B,KAAK,GAAG,CAAC,CAAA;QADhC;;;;mBAAgB,KAAK;WAAQ;QAVzC;;;;mBAAO,mBAAmB;WAAA;QAE1B,oEAAoE;QACpE,kDAAkD;QAClD;;;;mBAAS,GAAG;WAAA;QACZ;;;;mBAAS,IAAI;WAAA;IAOb,CAAC;CACF;AAdD,8CAcC"}
@@ -0,0 +1,21 @@
1
+ import { ScopeMissingError } from './scope-missing-error.js';
2
+ import { ScopeMatchingOptionsByResource } from './utilities.js';
3
+ export { ScopeMissingError };
4
+ /**
5
+ * Utility class to manage a set of scopes and check if they match specific
6
+ * options for a given resource.
7
+ */
8
+ export declare class ScopesSet extends Set<string> {
9
+ /**
10
+ * Check if the container has a scope that matches the given options for a
11
+ * specific resource.
12
+ */
13
+ matches<R extends keyof ScopeMatchingOptionsByResource>(resource: R, options: ScopeMatchingOptionsByResource[R]): boolean;
14
+ assert<R extends keyof ScopeMatchingOptionsByResource>(resource: R, options: ScopeMatchingOptionsByResource[R]): void;
15
+ some(fn: (scope: string) => boolean): boolean;
16
+ every(fn: (scope: string) => boolean): boolean;
17
+ filter(fn: (scope: string) => boolean): Generator<string, void, unknown>;
18
+ map<O>(fn: (scope: string) => O): Generator<O, void, unknown>;
19
+ static fromString(string?: string): ScopesSet;
20
+ }
21
+ //# sourceMappingURL=scopes-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes-set.d.ts","sourceRoot":"","sources":["../src/scopes-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EACL,8BAA8B,EAG/B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAE5B;;;GAGG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM,CAAC;IACxC;;;OAGG;IACI,OAAO,CAAC,CAAC,SAAS,MAAM,8BAA8B,EAC3D,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,8BAA8B,CAAC,CAAC,CAAC,GACzC,OAAO;IAOH,MAAM,CAAC,CAAC,SAAS,MAAM,8BAA8B,EAC1D,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,8BAA8B,CAAC,CAAC,CAAC;IAQrC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO;IAK7C,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO;IAK7C,MAAM,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO;IAIrC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC;IAIvC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS;CAG9C"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScopesSet = exports.ScopeMissingError = void 0;
4
+ const scope_missing_error_js_1 = require("./scope-missing-error.js");
5
+ Object.defineProperty(exports, "ScopeMissingError", { enumerable: true, get: function () { return scope_missing_error_js_1.ScopeMissingError; } });
6
+ const utilities_js_1 = require("./utilities.js");
7
+ /**
8
+ * Utility class to manage a set of scopes and check if they match specific
9
+ * options for a given resource.
10
+ */
11
+ class ScopesSet extends Set {
12
+ /**
13
+ * Check if the container has a scope that matches the given options for a
14
+ * specific resource.
15
+ */
16
+ matches(resource, options) {
17
+ for (const scope of this) {
18
+ if ((0, utilities_js_1.scopeMatches)(scope, resource, options))
19
+ return true;
20
+ }
21
+ return false;
22
+ }
23
+ assert(resource, options) {
24
+ if (!this.matches(resource, options)) {
25
+ const scope = (0, utilities_js_1.scopeNeededFor)(resource, options);
26
+ throw new scope_missing_error_js_1.ScopeMissingError(scope);
27
+ }
28
+ }
29
+ some(fn) {
30
+ for (const scope of this)
31
+ if (fn(scope))
32
+ return true;
33
+ return false;
34
+ }
35
+ every(fn) {
36
+ for (const scope of this)
37
+ if (!fn(scope))
38
+ return false;
39
+ return true;
40
+ }
41
+ *filter(fn) {
42
+ for (const scope of this)
43
+ if (fn(scope))
44
+ yield scope;
45
+ }
46
+ *map(fn) {
47
+ for (const scope of this)
48
+ yield fn(scope);
49
+ }
50
+ static fromString(string) {
51
+ return new ScopesSet(string?.split(' '));
52
+ }
53
+ }
54
+ exports.ScopesSet = ScopesSet;
55
+ //# sourceMappingURL=scopes-set.js.map