@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
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @atproto/oauth-scopes
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3806](https://github.com/bluesky-social/atproto/pull/3806) [`1899b1fc1`](https://github.com/bluesky-social/atproto/commit/1899b1fc16bc5cd7bb930ec697898766c3a05add) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Initial implementation of library used to parse ATProto OAuth scopes
package/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Dual MIT/Apache-2.0 License
2
+
3
+ Copyright (c) 2022-2025 Bluesky Social PBC, and Contributors
4
+
5
+ Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
6
+
7
+ Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.
@@ -0,0 +1,16 @@
1
+ export * from './scope-missing-error.js';
2
+ export * from './permission-set.js';
3
+ export * from './permission-set-transition.js';
4
+ export * from './scopes-set.js';
5
+ export * from './parser.js';
6
+ export * from './syntax.js';
7
+ export * from './utilities.js';
8
+ export * from './resources/account-scope.js';
9
+ export * from './resources/blob-scope.js';
10
+ export * from './resources/identity-scope.js';
11
+ export * from './resources/repo-scope.js';
12
+ export * from './resources/rpc-scope.js';
13
+ export * from './lib/mime.js';
14
+ export * from './lib/did.js';
15
+ export * from './lib/nsid.js';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAE9B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AAExC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
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("./scope-missing-error.js"), exports);
18
+ __exportStar(require("./permission-set.js"), exports);
19
+ __exportStar(require("./permission-set-transition.js"), exports);
20
+ __exportStar(require("./scopes-set.js"), exports);
21
+ __exportStar(require("./parser.js"), exports);
22
+ __exportStar(require("./syntax.js"), exports);
23
+ __exportStar(require("./utilities.js"), exports);
24
+ __exportStar(require("./resources/account-scope.js"), exports);
25
+ __exportStar(require("./resources/blob-scope.js"), exports);
26
+ __exportStar(require("./resources/identity-scope.js"), exports);
27
+ __exportStar(require("./resources/repo-scope.js"), exports);
28
+ __exportStar(require("./resources/rpc-scope.js"), exports);
29
+ __exportStar(require("./lib/mime.js"), exports);
30
+ __exportStar(require("./lib/did.js"), exports);
31
+ __exportStar(require("./lib/nsid.js"), exports);
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAwC;AACxC,sDAAmC;AACnC,iEAA8C;AAC9C,kDAA+B;AAC/B,8CAA2B;AAC3B,8CAA2B;AAC3B,iDAA8B;AAE9B,+DAA4C;AAC5C,4DAAyC;AACzC,gEAA6C;AAC7C,4DAAyC;AACzC,2DAAwC;AAExC,gDAA6B;AAC7B,+CAA4B;AAC5B,gDAA6B"}
@@ -0,0 +1,3 @@
1
+ export type DIDLike = `did:${string}`;
2
+ export declare const isDIDLike: (value: string) => value is DIDLike;
3
+ //# sourceMappingURL=did.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../src/lib/did.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,OAAO,MAAM,EAAE,CAAA;AACrC,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,KAAK,IAAI,OACzB,CAAA"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDIDLike = void 0;
4
+ const isDIDLike = (value) => value.startsWith('did:');
5
+ exports.isDIDLike = isDIDLike;
6
+ //# sourceMappingURL=did.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did.js","sourceRoot":"","sources":["../../src/lib/did.ts"],"names":[],"mappings":";;;AACO,MAAM,SAAS,GAAG,CAAC,KAAa,EAAoB,EAAE,CAC3D,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;AADb,QAAA,SAAS,aACI"}
@@ -0,0 +1,7 @@
1
+ export type Mime = `${string}/${string}`;
2
+ export declare function isMime(value: string): value is Mime;
3
+ export type Accept = '*/*' | `${string}/*` | Mime;
4
+ export declare function isAccept(value: string): value is Accept;
5
+ export declare function matchesAccept(accept: Accept, mime: string): boolean;
6
+ export declare function matchesAnyAccept(acceptable: Iterable<Accept>, mime: string): boolean;
7
+ //# sourceMappingURL=mime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../src/lib/mime.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAA;AAExC,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAEnD;AAED,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,GAAG,MAAM,IAAI,GAAG,IAAI,CAAA;AAEjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAIvD;AAiBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnE;AAmBD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC5B,IAAI,EAAE,MAAM,GACX,OAAO,CAET"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ // @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
+ function isStringSlashString(value) {
9
+ const slashIndex = value.indexOf('/');
10
+ if (slashIndex === -1)
11
+ return false; // Missing slash
12
+ if (slashIndex === 0)
13
+ return false; // No leading part before the slash
14
+ if (slashIndex === value.length - 1)
15
+ return false; // No trailing part after the slash
16
+ if (value.includes('/', slashIndex + 1))
17
+ return false; // More than one slash
18
+ if (value.includes(' '))
19
+ return false; // Spaces are not allowed
20
+ return true;
21
+ }
22
+ function isMime(value) {
23
+ return isStringSlashString(value) && !value.includes('*');
24
+ }
25
+ function isAccept(value) {
26
+ if (value === '*/*')
27
+ return true; // Fast path for the most common case
28
+ if (!isStringSlashString(value))
29
+ return false;
30
+ return !value.includes('*') || value.endsWith('/*');
31
+ }
32
+ /**
33
+ * @note "unsafe" in that it does not check if either {@link accept} or
34
+ * {@link mime} are actually valid values (and could, therefore, lead to false
35
+ * positives if forged values are used).
36
+ */
37
+ function matchesAcceptUnsafe(accept, mime) {
38
+ if (accept === '*/*') {
39
+ return true;
40
+ }
41
+ if (accept.endsWith('/*')) {
42
+ return mime.startsWith(accept.slice(0, -1));
43
+ }
44
+ return accept === mime;
45
+ }
46
+ function matchesAccept(accept, mime) {
47
+ return isMime(mime) && matchesAcceptUnsafe(accept, mime);
48
+ }
49
+ /**
50
+ * @note "unsafe" in that it does not check if either {@link accept} or
51
+ * {@link mime} are actually valid values (and could, therefore, lead to false
52
+ * positives if forged values are used).
53
+ */
54
+ function matchesAnyAcceptUnsafe(acceptable, mime) {
55
+ for (const accept of acceptable) {
56
+ if (matchesAcceptUnsafe(accept, mime)) {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ }
62
+ function matchesAnyAccept(acceptable, mime) {
63
+ return isMime(mime) && matchesAnyAcceptUnsafe(acceptable, m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Ac,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,SAAgB,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,SAAgB,gBAAgB,CAC9B,UAA4B,EAC5B,IAAY;IAEZ,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACjE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type NSID = `${string}.${string}`;
2
+ export declare const isNSID: (value: string) => value is NSID;
3
+ //# sourceMappingURL=nsid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nsid.d.ts","sourceRoot":"","sources":["../../src/lib/nsid.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAA;AACxC,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,KAAG,KAAK,IAAI,IAI1B,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNSID = void 0;
4
+ const isNSID = (value) => value.includes('.') &&
5
+ !value.includes(' ') &&
6
+ !value.startsWith('.') &&
7
+ !value.endsWith('.');
8
+ exports.isNSID = isNSID;
9
+ //# sourceMappingURL=nsid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nsid.js","sourceRoot":"","sources":["../../src/lib/nsid.ts"],"names":[],"mappings":";;;AACO,MAAM,MAAM,GAAG,CAAC,KAAa,EAAiB,EAAE,CACrD,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;IACnB,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpB,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;IACtB,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAJT,QAAA,MAAM,UAIG"}
@@ -0,0 +1,3 @@
1
+ export declare function minIdx(a: number, b: number): number;
2
+ export declare function toRecord(iterable: Iterable<[key: string, value: string]>): Record<string, [string, ...string[]]>;
3
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,GAC/C,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAUvC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.minIdx = minIdx;
4
+ exports.toRecord = toRecord;
5
+ function minIdx(a, b) {
6
+ if (a === -1)
7
+ return b;
8
+ if (b === -1)
9
+ return a;
10
+ return Math.min(a, b);
11
+ }
12
+ function toRecord(iterable) {
13
+ const record = Object.create(null);
14
+ for (const [key, value] of iterable) {
15
+ if (Object.hasOwn(record, key)) {
16
+ record[key].push(value);
17
+ }
18
+ else {
19
+ record[key] = [value];
20
+ }
21
+ }
22
+ return record;
23
+ }
24
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/lib/util.ts"],"names":[],"mappings":";;AAAA,wBAIC;AAED,4BAYC;AAlBD,SAAgB,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,SAAgB,QAAQ,CACtB,QAAgD;IAEhD,MAAM,MAAM,GAA0C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACzE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;QACpC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACvB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { NeRoArray, ResourceSyntax, ScopeForResource } from './syntax.js';
2
+ type InferStringPredicate<T extends undefined | ((value: string) => boolean)> = T extends ((value: string) => value is infer U extends string) ? U : string;
3
+ type ParamsSchema = Record<string, {
4
+ multiple: false;
5
+ required: boolean;
6
+ default?: string;
7
+ normalize?: (value: string) => string;
8
+ validate?: (value: string) => boolean;
9
+ } | {
10
+ multiple: true;
11
+ required: boolean;
12
+ default?: NeRoArray<string>;
13
+ normalize?: (value: NeRoArray<string>) => NeRoArray<string>;
14
+ validate?: (value: string) => boolean;
15
+ }>;
16
+ type ParsedParams<S extends ParamsSchema> = {
17
+ [K in keyof S]: (S[K]['required'] extends true ? never : 'default' extends keyof S[K] ? S[K]['default'] : undefined) | (S[K]['multiple'] extends true ? NeRoArray<InferStringPredicate<S[K]['validate']>> : InferStringPredicate<S[K]['validate']>);
18
+ } & NonNullable<unknown>;
19
+ export declare class Parser<R extends string, S extends ParamsSchema> {
20
+ readonly resource: R;
21
+ readonly schema: S;
22
+ readonly positionalName?: (keyof S & string) | undefined;
23
+ readonly schemaKeys: ReadonlyArray<keyof S & string>;
24
+ constructor(resource: R, schema: S, positionalName?: (keyof S & string) | undefined);
25
+ format(values: ParsedParams<S>): ScopeForResource<R>;
26
+ parse(syntax: ResourceSyntax): { [K in keyof S]: (S[K]["required"] extends true ? never : "default" extends keyof S[K] ? S[K][keyof S[K] & "default"] : undefined) | (S[K]["multiple"] extends true ? NeRoArray<InferStringPredicate<S[K]["validate"]>> : InferStringPredicate<S[K]["validate"]>); } | null;
27
+ parseString(scope: string): ParsedParams<S> | null;
28
+ }
29
+ export declare function knownValuesValidator<T extends string>(values: Iterable<T>): (value: string) => value is T;
30
+ export {};
31
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,cAAc,EACd,gBAAgB,EAEjB,MAAM,aAAa,CAAA;AAEpB,KAAK,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAC1E,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,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AAM,EAAE,CAAC,SAAS,YAAY;IAIxD,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,cAAc,CAAC,GAAE,MAAM,CAAC,GAAG,MAAM;IAL5C,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;gBAGzC,QAAQ,EAAE,CAAC,EACX,MAAM,EAAE,CAAC,EACT,cAAc,CAAC,GAAE,MAAM,CAAC,GAAG,MAAM,aAAA;IAK5C,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;IAuCpD,KAAK,CAAC,MAAM,EAAE,cAAc,MA7D3B,CAAC;IAgGF,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI;CAInD;AAiBD,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,IAEhE,OAAO,MAAM,KAAG,KAAK,IAAI,CAAC,CACnC"}
package/dist/parser.js ADDED
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Parser = void 0;
4
+ exports.knownValuesValidator = knownValuesValidator;
5
+ const syntax_js_1 = require("./syntax.js");
6
+ class Parser {
7
+ constructor(resource, schema, positionalName) {
8
+ Object.defineProperty(this, "resource", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: resource
13
+ });
14
+ Object.defineProperty(this, "schema", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: schema
19
+ });
20
+ Object.defineProperty(this, "positionalName", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: positionalName
25
+ });
26
+ Object.defineProperty(this, "schemaKeys", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ this.schemaKeys = Object.keys(schema);
33
+ }
34
+ format(values) {
35
+ // Build params
36
+ const params = [];
37
+ for (const key of this.schemaKeys) {
38
+ const value = values[key];
39
+ // Ignore undefined values
40
+ if (value === undefined)
41
+ continue;
42
+ const schema = this.schema[key];
43
+ // @TODO: when the value is an array, we could remove duplicates
44
+ // Normalize the value if a normalization function is provided
45
+ const normalized = schema.normalize
46
+ ? schema.normalize(value)
47
+ : value;
48
+ // Ignore values that are equal to the default value
49
+ if (!schema.required) {
50
+ if (schema.default === normalized)
51
+ continue;
52
+ if (schema.multiple &&
53
+ schema.default &&
54
+ arrayParamEquals(schema.default, normalized)) {
55
+ continue;
56
+ }
57
+ }
58
+ params.push([key, normalized]);
59
+ }
60
+ return (0, syntax_js_1.formatScope)(this.resource, params, this.positionalName);
61
+ }
62
+ parse(syntax) {
63
+ if (!syntax.is(this.resource))
64
+ return null;
65
+ if (syntax.containsParamsOtherThan(this.schemaKeys))
66
+ return null;
67
+ const result = Object.create(null);
68
+ for (const key of this.schemaKeys) {
69
+ const definition = this.schema[key];
70
+ const value = definition.multiple
71
+ ? syntax.getMulti(key, key === this.positionalName)
72
+ : syntax.getSingle(key, key === this.positionalName);
73
+ if (value === null)
74
+ return null; // Value is not valid
75
+ if (value === undefined && definition.required)
76
+ return null;
77
+ if (value !== undefined && definition.validate) {
78
+ if (definition.multiple) {
79
+ if (!value.every(definition.validate)) {
80
+ return null;
81
+ }
82
+ }
83
+ else {
84
+ if (!definition.validate(value)) {
85
+ return null;
86
+ }
87
+ }
88
+ }
89
+ result[key] = value ?? definition.default;
90
+ }
91
+ return result;
92
+ }
93
+ parseString(scope) {
94
+ const syntax = syntax_js_1.ResourceSyntax.fromString(scope);
95
+ return this.parse(syntax);
96
+ }
97
+ }
98
+ exports.Parser = Parser;
99
+ /**
100
+ * Two param arrays are considered equal if they contain the same values,
101
+ * regardless of the order and duplicates.
102
+ * @param a - The first array to compare.
103
+ * @param b - The second array to compare.
104
+ */
105
+ function arrayParamEquals(a, b) {
106
+ for (const item of a)
107
+ if (!b.includes(item))
108
+ return false;
109
+ for (const item of b)
110
+ if (!a.includes(item))
111
+ return false;
112
+ return true;
113
+ }
114
+ function knownValuesValidator(values) {
115
+ const set = new Set(values);
116
+ return (value) => set.has(value);
117
+ }
118
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";;;AAkJA,oDAGC;AArJD,2CAKoB;AAmCpB,MAAa,MAAM;IAGjB,YACW,QAAW,EACX,MAAS,EACT,cAAiC;QAF1C;;;;mBAAS,QAAQ;WAAG;QACpB;;;;mBAAS,MAAM;WAAG;QAClB;;;;mBAAS,cAAc;WAAmB;QALnC;;;;;WAA2C;QAOlD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACvC,CAAC;IAED,MAAM,CAAC,MAAuB;QAC5B,eAAe;QACf,MAAM,MAAM,GAGN,EAAE,CAAA;QAER,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;YACzB,0BAA0B;YAC1B,IAAI,KAAK,KAAK,SAAS;gBAAE,SAAQ;YAEjC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAE/B,gEAAgE;YAEhE,8DAA8D;YAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS;gBACjC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAY,CAAC;gBAChC,CAAC,CAAC,KAAK,CAAA;YAET,oDAAoD;YACpD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACrB,IAAI,MAAM,CAAC,OAAO,KAAK,UAAU;oBAAE,SAAQ;gBAC3C,IACE,MAAM,CAAC,QAAQ;o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,CAAE,KAA2B,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC7D,OAAO,IAAI,CAAA;oBACb,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAe,CAAC,EAAE,CAAC;wBAC1C,OAAO,IAAI,CAAA;oBACb,CAAC;gBACH,CAAC;YACH,CAAC;YAED,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,OAAO,CAAA;QAC3C,CAAC;QAED,OAAO,MAAyB,CAAA;IAClC,CAAC;IAED,WAAW,CAAC,KAAa;QACvB,MAAM,MAAM,GAAG,0BAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;CACF;AAzFD,wBAyFC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,CAAqB,EACrB,CAAqB;IAErB,KAAK,MAAM,IAAI,IAAI,CAAC;QAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAA;IACzD,KAAK,MAAM,IAAI,IAAI,CAAC;QAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAA;IACzD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAgB,oBAAoB,CAAmB,MAAmB;IACxE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,CAAA;IACnC,OAAO,CAAC,KAAa,EAAc,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACtD,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { AccountScopeMatch, BlobScopeMatch, PermissionSet, RepoScopeMatch, RpcScopeMatch } from './permission-set.js';
2
+ /**
3
+ * Overrides the default permission set to allow transitional scopes to be used
4
+ * in place of the generic scopes.
5
+ */
6
+ export declare class PermissionSetTransition extends PermissionSet {
7
+ get hasTransitionGeneric(): boolean;
8
+ get hasTransitionEmail(): boolean;
9
+ get hasTransitionChatBsky(): boolean;
10
+ allowsAccount(options: AccountScopeMatch): boolean;
11
+ allowsBlob(options: BlobScopeMatch): boolean;
12
+ allowsRepo(options: RepoScopeMatch): boolean;
13
+ allowsRpc(options: RpcScopeMatch): boolean;
14
+ }
15
+ //# sourceMappingURL=permission-set-transition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-set-transition.d.ts","sourceRoot":"","sources":["../src/permission-set-transition.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACd,MAAM,qBAAqB,CAAA;AAE5B;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,IAAI,oBAAoB,IAAI,OAAO,CAElC;IAED,IAAI,kBAAkB,IAAI,OAAO,CAEhC;IAED,IAAI,qBAAqB,IAAI,OAAO,CAEnC;IAEQ,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO;IAQlD,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAQ5C,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAQ5C,SAAS,CAAC,OAAO,EAAE,aAAa;CAiB1C"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PermissionSetTransition = void 0;
4
+ const permission_set_js_1 = require("./permission-set.js");
5
+ /**
6
+ * Overrides the default permission set to allow transitional scopes to be used
7
+ * in place of the generic scopes.
8
+ */
9
+ class PermissionSetTransition extends permission_set_js_1.PermissionSet {
10
+ get hasTransitionGeneric() {
11
+ return this.scopes.has('transition:generic');
12
+ }
13
+ get hasTransitionEmail() {
14
+ return this.scopes.has('transition:email');
15
+ }
16
+ get hasTransitionChatBsky() {
17
+ return this.scopes.has('transition:chat.bsky');
18
+ }
19
+ allowsAccount(options) {
20
+ if (options.attr === 'email' && this.hasTransitionEmail) {
21
+ return true;
22
+ }
23
+ return super.allowsAccount(options);
24
+ }
25
+ allowsBlob(options) {
26
+ if (this.hasTransitionGeneric) {
27
+ return true;
28
+ }
29
+ return super.allowsBlob(options);
30
+ }
31
+ allowsRepo(options) {
32
+ if (this.hasTransitionGeneric) {
33
+ return true;
34
+ }
35
+ return super.allowsRepo(options);
36
+ }
37
+ allowsRpc(options) {
38
+ const { lxm } = options;
39
+ if (this.hasTransitionGeneric && lxm === '*') {
40
+ return true;
41
+ }
42
+ if (this.hasTransitionGeneric && !lxm.startsWith('chat.bsky.')) {
43
+ return true;
44
+ }
45
+ if (this.hasTransitionChatBsky && lxm.startsWith('chat.bsky.')) {
46
+ return true;
47
+ }
48
+ return super.allowsRpc(options);
49
+ }
50
+ }
51
+ exports.PermissionSetTransition = PermissionSetTransition;
52
+ //# sourceMappingURL=permission-set-transition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-set-transition.js","sourceRoot":"","sources":["../src/permission-set-transition.ts"],"names":[],"mappings":";;;AAAA,2DAM4B;AAE5B;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,iCAAa;IACxD,IAAI,oBAAoB;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC5C,CAAC;IAED,IAAI,qBAAqB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;IAChD,CAAC;IAEQ,aAAa,CAAC,OAA0B;QAC/C,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IACrC,CAAC;IAEQ,UAAU,CAAC,OAAuB;QACzC,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC;IAEQ,UAAU,CAAC,OAAuB;QACzC,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC;IAEQ,SAAS,CAAC,OAAsB;QACvC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;QAEvB,IAAI,IAAI,CAAC,oBAAoB,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;YAC7C,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,IAAI,CAAC,oBAAoB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,IAAI,CAAC,qBAAqB,IAAI,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;CACF;AAtDD,0DAsDC"}
@@ -0,0 +1,22 @@
1
+ import { AccountScopeMatch } from './resources/account-scope.js';
2
+ import { BlobScopeMatch } from './resources/blob-scope.js';
3
+ import { IdentityScopeMatch } from './resources/identity-scope.js';
4
+ import { RepoScopeMatch } from './resources/repo-scope.js';
5
+ import { RpcScopeMatch } from './resources/rpc-scope.js';
6
+ import { ScopesSet } from './scopes-set.js';
7
+ export type { AccountScopeMatch, BlobScopeMatch, IdentityScopeMatch, RepoScopeMatch, RpcScopeMatch, };
8
+ export declare class PermissionSet {
9
+ readonly scopes: ScopesSet;
10
+ constructor(scopes?: null | string | Iterable<string>);
11
+ allowsAccount(options: AccountScopeMatch): boolean;
12
+ assertAccount(options: AccountScopeMatch): void;
13
+ allowsIdentity(options: IdentityScopeMatch): boolean;
14
+ assertIdentity(options: IdentityScopeMatch): void;
15
+ allowsBlob(options: BlobScopeMatch): boolean;
16
+ assertBlob(options: BlobScopeMatch): void;
17
+ allowsRepo(options: RepoScopeMatch): boolean;
18
+ assertRepo(options: RepoScopeMatch): void;
19
+ allowsRpc(options: RpcScopeMatch): boolean;
20
+ assertRpc(options: RpcScopeMatch): void;
21
+ }
22
+ //# sourceMappingURL=permission-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-set.d.ts","sourceRoot":"","sources":["../src/permission-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAa,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAEL,kBAAkB,EACnB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAa,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAY,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,aAAa,GACd,CAAA;AAED,qBAAa,aAAa;IACxB,SAAgB,MAAM,EAAE,SAAS,CAAA;gBAErB,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAM9C,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO;IAGlD,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAO/C,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO;IAGpD,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAOjD,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAG5C,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAOzC,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAG5C,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAOzC,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;IAG1C,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;CAM/C"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PermissionSet = void 0;
4
+ const account_scope_js_1 = require("./resources/account-scope.js");
5
+ const blob_scope_js_1 = require("./resources/blob-scope.js");
6
+ const identity_scope_js_1 = require("./resources/identity-scope.js");
7
+ const repo_scope_js_1 = require("./resources/repo-scope.js");
8
+ const rpc_scope_js_1 = require("./resources/rpc-scope.js");
9
+ const scope_missing_error_js_1 = require("./scope-missing-error.js");
10
+ const scopes_set_js_1 = require("./scopes-set.js");
11
+ class PermissionSet {
12
+ constructor(scopes) {
13
+ Object.defineProperty(this, "scopes", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ this.scopes = new scopes_set_js_1.ScopesSet(typeof scopes === 'string' ? scopes.split(' ') : scopes);
20
+ }
21
+ allowsAccount(options) {
22
+ return this.scopes.matches('account', options);
23
+ }
24
+ assertAccount(options) {
25
+ if (!this.allowsAccount(options)) {
26
+ const scope = account_scope_js_1.AccountScope.scopeNeededFor(options);
27
+ throw new scope_missing_error_js_1.ScopeMissingError(scope);
28
+ }
29
+ }
30
+ allowsIdentity(options) {
31
+ return this.scopes.matches('identity', options);
32
+ }
33
+ assertIdentity(options) {
34
+ if (!this.allowsIdentity(options)) {
35
+ const scope = identity_scope_js_1.IdentityScope.scopeNeededFor(options);
36
+ throw new scope_missing_error_js_1.ScopeMissingError(scope);
37
+ }
38
+ }
39
+ allowsBlob(options) {
40
+ return this.scopes.matches('blob', options);
41
+ }
42
+ assertBlob(options) {
43
+ if (!this.allowsBlob(options)) {
44
+ const scope = blob_scope_js_1.BlobScope.scopeNeededFor(options);
45
+ throw new scope_missing_error_js_1.ScopeMissingError(scope);
46
+ }
47
+ }
48
+ allowsRepo(options) {
49
+ return this.scopes.matches('repo', options);
50
+ }
51
+ assertRepo(options) {
52
+ if (!this.allowsRepo(options)) {
53
+ const scope = repo_scope_js_1.RepoScope.scopeNeededFor(options);
54
+ throw new scope_missing_error_js_1.ScopeMissingError(scope);
55
+ }
56
+ }
57
+ allowsRpc(options) {
58
+ return this.scopes.matches('rpc', options);
59
+ }
60
+ assertRpc(options) {
61
+ if (!this.allowsRpc(options)) {
62
+ const scope = rpc_scope_js_1.RpcScope.scopeNeededFor(options);
63
+ throw new scope_missing_error_js_1.ScopeMissingError(scope);
64
+ }
65
+ }
66
+ }
67
+ exports.PermissionSet = PermissionSet;
68
+ //# sourceMappingURL=permission-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-set.js","sourceRoot":"","sources":["../src/permission-set.ts"],"names":[],"mappings":";;;AAAA,mEAA8E;AAC9E,6DAAqE;AACrE,qEAGsC;AACtC,6DAAqE;AACrE,2DAAkE;AAClE,qEAA4D;AAC5D,mDAA2C;AAU3C,MAAa,aAAa;IAGxB,YAAY,MAAyC;QAFrC;;;;;WAAiB;QAG/B,IAAI,CAAC,MAAM,GAAG,IAAI,yBAAS,CACzB,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CACxD,CAAA;IACH,CAAC;IAEM,aAAa,CAAC,OAA0B;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC;IACM,aAAa,CAAC,OAA0B;QAC7C,IAAI,CAAC,IAAI,CAAC,aAAa,C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AAC,OAAsB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC;IACM,SAAS,CAAC,OAAsB;QACrC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7B,MAAM,KAAK,GAAG,uBAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;YAC9C,MAAM,IAAI,0CAAiB,CAAC,KAAK,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;CACF;AA1DD,sCA0DC"}
@@ -0,0 +1,35 @@
1
+ import { Parser } from '../parser.js';
2
+ import { ResourceSyntax } from '../syntax.js';
3
+ declare const ACCOUNT_ATTRIBUTES: readonly ["email", "repo", "status"];
4
+ export type AccountAttribute = (typeof ACCOUNT_ATTRIBUTES)[number];
5
+ declare const ACCOUNT_ACTIONS: readonly ["read", "manage"];
6
+ export type AccountAction = (typeof ACCOUNT_ACTIONS)[number];
7
+ export declare const accountParser: Parser<"account", {
8
+ attr: {
9
+ multiple: false;
10
+ required: true;
11
+ validate: (value: string) => value is "email" | "repo" | "status";
12
+ };
13
+ action: {
14
+ multiple: false;
15
+ required: false;
16
+ validate: (value: string) => value is "read" | "manage";
17
+ default: "read";
18
+ };
19
+ }>;
20
+ export type AccountScopeMatch = {
21
+ attr: AccountAttribute;
22
+ action: AccountAction;
23
+ };
24
+ export declare class AccountScope {
25
+ readonly attr: AccountAttribute;
26
+ readonly action: AccountAction;
27
+ constructor(attr: AccountAttribute, action: AccountAction);
28
+ matches(options: AccountScopeMatch): boolean;
29
+ toString(): import("../syntax.js").ScopeForResource<"account">;
30
+ static fromString(scope: string): AccountScope | null;
31
+ static fromSyntax(syntax: ResourceSyntax): AccountScope | null;
32
+ static scopeNeededFor(options: AccountScopeMatch): string;
33
+ }
34
+ export {};
35
+ //# sourceMappingURL=account-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-scope.d.ts","sourceRoot":"","sources":["../../src/resources/account-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwB,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAsB,MAAM,cAAc,CAAA;AAEjE,QAAA,MAAM,kBAAkB,sCAAsD,CAAA;AAC9E,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AAElE,QAAA,MAAM,eAAe,6BAA6C,CAAA;AAClE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAE5D,eAAO,MAAM,aAAa;;;;;;;;;;;;EAgBzB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,EAAE,aAAa,CAAA;CACtB,CAAA;AAED,qBAAa,YAAY;aAEL,IAAI,EAAE,gBAAgB;aACtB,MAAM,EAAE,aAAa;gBADrB,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,aAAa;IAGvC,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO;IAO5C,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,iBAAiB,GAAG,MAAM;CAG1D"}