cogens 0.2.0 → 0.3.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.
Files changed (158) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +35 -7
  3. package/dist/admin/app.d.ts +21 -0
  4. package/dist/admin/app.d.ts.map +1 -0
  5. package/dist/admin/app.js +702 -0
  6. package/dist/admin/app.js.map +1 -0
  7. package/dist/admin/assets.d.ts +17 -0
  8. package/dist/admin/assets.d.ts.map +1 -0
  9. package/dist/admin/assets.js +51 -0
  10. package/dist/admin/assets.js.map +1 -0
  11. package/dist/admin/fields.d.ts +29 -0
  12. package/dist/admin/fields.d.ts.map +1 -0
  13. package/dist/admin/fields.js +130 -0
  14. package/dist/admin/fields.js.map +1 -0
  15. package/dist/admin/forms.d.ts +18 -0
  16. package/dist/admin/forms.d.ts.map +1 -0
  17. package/dist/admin/forms.js +53 -0
  18. package/dist/admin/forms.js.map +1 -0
  19. package/dist/admin/index.d.ts +15 -0
  20. package/dist/admin/index.d.ts.map +1 -0
  21. package/dist/admin/index.js +13 -0
  22. package/dist/admin/index.js.map +1 -0
  23. package/dist/admin/rules.d.ts +24 -0
  24. package/dist/admin/rules.d.ts.map +1 -0
  25. package/dist/admin/rules.js +51 -0
  26. package/dist/admin/rules.js.map +1 -0
  27. package/dist/admin/types.d.ts +147 -0
  28. package/dist/admin/types.d.ts.map +1 -0
  29. package/dist/admin/types.js +2 -0
  30. package/dist/admin/types.js.map +1 -0
  31. package/dist/admin/views.d.ts +138 -0
  32. package/dist/admin/views.d.ts.map +1 -0
  33. package/dist/admin/views.js +225 -0
  34. package/dist/admin/views.js.map +1 -0
  35. package/dist/auth/handoff.d.ts +27 -0
  36. package/dist/auth/handoff.d.ts.map +1 -0
  37. package/dist/auth/handoff.js +41 -0
  38. package/dist/auth/handoff.js.map +1 -0
  39. package/dist/auth/index.d.ts +10 -0
  40. package/dist/auth/index.d.ts.map +1 -0
  41. package/dist/auth/index.js +10 -0
  42. package/dist/auth/index.js.map +1 -0
  43. package/dist/auth/password.d.ts +48 -0
  44. package/dist/auth/password.d.ts.map +1 -0
  45. package/dist/auth/password.js +154 -0
  46. package/dist/auth/password.js.map +1 -0
  47. package/dist/auth/principal.d.ts +30 -0
  48. package/dist/auth/principal.d.ts.map +1 -0
  49. package/dist/auth/principal.js +30 -0
  50. package/dist/auth/principal.js.map +1 -0
  51. package/dist/auth/session.d.ts +68 -0
  52. package/dist/auth/session.d.ts.map +1 -0
  53. package/dist/auth/session.js +92 -0
  54. package/dist/auth/session.js.map +1 -0
  55. package/dist/core/access/ability.d.ts +24 -0
  56. package/dist/core/access/ability.d.ts.map +1 -0
  57. package/dist/core/access/ability.js +64 -0
  58. package/dist/core/access/ability.js.map +1 -0
  59. package/dist/core/access/can.d.ts +41 -0
  60. package/dist/core/access/can.d.ts.map +1 -0
  61. package/dist/core/access/can.js +38 -0
  62. package/dist/core/access/can.js.map +1 -0
  63. package/dist/core/access/compile.d.ts +12 -0
  64. package/dist/core/access/compile.d.ts.map +1 -0
  65. package/dist/core/access/compile.js +53 -0
  66. package/dist/core/access/compile.js.map +1 -0
  67. package/dist/core/access/permits.d.ts +24 -0
  68. package/dist/core/access/permits.d.ts.map +1 -0
  69. package/dist/core/access/permits.js +29 -0
  70. package/dist/core/access/permits.js.map +1 -0
  71. package/dist/core/access/when.d.ts +6 -0
  72. package/dist/core/access/when.d.ts.map +1 -0
  73. package/dist/core/access/when.js +64 -0
  74. package/dist/core/access/when.js.map +1 -0
  75. package/dist/core/access/where.d.ts +25 -0
  76. package/dist/core/access/where.d.ts.map +1 -0
  77. package/dist/core/access/where.js +81 -0
  78. package/dist/core/access/where.js.map +1 -0
  79. package/dist/core/columns.d.ts +6 -0
  80. package/dist/core/columns.d.ts.map +1 -0
  81. package/dist/core/columns.js +6 -0
  82. package/dist/core/columns.js.map +1 -0
  83. package/dist/core/config/define.d.ts +101 -0
  84. package/dist/core/config/define.d.ts.map +1 -0
  85. package/dist/core/config/define.js +97 -0
  86. package/dist/core/config/define.js.map +1 -0
  87. package/dist/core/config/field.d.ts +87 -0
  88. package/dist/core/config/field.d.ts.map +1 -0
  89. package/dist/core/config/field.js +75 -0
  90. package/dist/core/config/field.js.map +1 -0
  91. package/dist/core/errors.d.ts +66 -0
  92. package/dist/core/errors.d.ts.map +1 -0
  93. package/dist/core/errors.js +94 -0
  94. package/dist/core/errors.js.map +1 -0
  95. package/dist/core/index.d.ts +31 -0
  96. package/dist/core/index.d.ts.map +1 -0
  97. package/dist/core/index.js +20 -0
  98. package/dist/core/index.js.map +1 -0
  99. package/dist/core/media/index.d.ts +36 -0
  100. package/dist/core/media/index.d.ts.map +1 -0
  101. package/dist/core/media/index.js +99 -0
  102. package/dist/core/media/index.js.map +1 -0
  103. package/dist/core/principal.d.ts +28 -0
  104. package/dist/core/principal.d.ts.map +1 -0
  105. package/dist/core/principal.js +25 -0
  106. package/dist/core/principal.js.map +1 -0
  107. package/dist/core/store/assets.d.ts +3 -0
  108. package/dist/core/store/assets.d.ts.map +1 -0
  109. package/dist/core/store/assets.js +3 -0
  110. package/dist/core/store/assets.js.map +1 -0
  111. package/dist/core/store/cms.d.ts +53 -0
  112. package/dist/core/store/cms.d.ts.map +1 -0
  113. package/dist/core/store/cms.js +154 -0
  114. package/dist/core/store/cms.js.map +1 -0
  115. package/dist/core/store/content.d.ts +57 -0
  116. package/dist/core/store/content.d.ts.map +1 -0
  117. package/dist/core/store/content.js +455 -0
  118. package/dist/core/store/content.js.map +1 -0
  119. package/dist/core/store/sql.d.ts +88 -0
  120. package/dist/core/store/sql.d.ts.map +1 -0
  121. package/dist/core/store/sql.js +149 -0
  122. package/dist/core/store/sql.js.map +1 -0
  123. package/dist/core/store/types.d.ts +107 -0
  124. package/dist/core/store/types.d.ts.map +1 -0
  125. package/dist/core/store/types.js +2 -0
  126. package/dist/core/store/types.js.map +1 -0
  127. package/dist/core/testing/index.d.ts +27 -0
  128. package/dist/core/testing/index.d.ts.map +1 -0
  129. package/dist/core/testing/index.js +60 -0
  130. package/dist/core/testing/index.js.map +1 -0
  131. package/dist/migrations-tool/bin.d.ts +3 -0
  132. package/dist/migrations-tool/bin.d.ts.map +1 -0
  133. package/dist/migrations-tool/bin.js +40 -0
  134. package/dist/migrations-tool/bin.js.map +1 -0
  135. package/dist/migrations-tool/index.d.ts +16 -0
  136. package/dist/migrations-tool/index.d.ts.map +1 -0
  137. package/dist/migrations-tool/index.js +24 -0
  138. package/dist/migrations-tool/index.js.map +1 -0
  139. package/dist/testing/db.d.ts +16 -0
  140. package/dist/testing/db.d.ts.map +1 -0
  141. package/dist/testing/db.js +43 -0
  142. package/dist/testing/db.js.map +1 -0
  143. package/dist/testing/index.d.ts +10 -0
  144. package/dist/testing/index.d.ts.map +1 -0
  145. package/dist/testing/index.js +8 -0
  146. package/dist/testing/index.js.map +1 -0
  147. package/package.json +33 -11
  148. package/src/admin/app.ts +181 -36
  149. package/src/admin/fields.ts +5 -2
  150. package/src/admin/index.ts +3 -2
  151. package/src/admin/types.ts +52 -1
  152. package/src/admin/views.ts +99 -21
  153. package/src/core/config/define.ts +1 -1
  154. package/src/core/config/field.ts +19 -2
  155. package/src/core/index.ts +1 -1
  156. package/src/core/store/cms.ts +1 -1
  157. package/src/migrations-tool/bin.ts +34 -0
  158. package/{scripts/print-migration.ts → src/migrations-tool/index.ts} +6 -19
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The decision engine: grants in, answers about one row out. This is the only
3
+ * file that imports CASL, and nothing here is exported by the package's index:
4
+ * a host sees `RuleSet`, whose methods take and return plain values.
5
+ */
6
+ import { createMongoAbility, mongoQueryMatcher, subject } from '@casl/ability';
7
+ import { permittedFieldsOf } from '@casl/ability/extra';
8
+ import { toMongo } from "./where.js";
9
+ /** Stands for "every field that is not a system field" in a grant with no field list. */
10
+ const ORDINARY = '*';
11
+ /**
12
+ * CASL's matcher knows equals and `$in` but not `$and` or `$or`, so those two are
13
+ * handled here and everything under them (the equals and `in` leaves) is still
14
+ * decided by CASL's own matcher.
15
+ */
16
+ const conditionsMatcher = conditions => {
17
+ const compile = (c) => {
18
+ if ('$and' in c) {
19
+ const parts = c.$and.map(compile);
20
+ return row => parts.every(p => p(row));
21
+ }
22
+ if ('$or' in c) {
23
+ const parts = c.$or.map(compile);
24
+ return row => parts.some(p => p(row));
25
+ }
26
+ return mongoQueryMatcher(c);
27
+ };
28
+ return compile(conditions);
29
+ };
30
+ export class RuleSet {
31
+ type;
32
+ grants;
33
+ ability;
34
+ constructor(type, grants) {
35
+ this.type = type;
36
+ this.grants = grants;
37
+ const rules = grants.map(g => ({
38
+ action: g.bySlug ? 'lookup' : g.operation,
39
+ subject: type,
40
+ ...(g.where === undefined ? {} : { conditions: toMongo(g.where) }),
41
+ fields: g.fields ?? [ORDINARY]
42
+ }));
43
+ this.ability = createMongoAbility(rules, { conditionsMatcher });
44
+ }
45
+ /** Whether any grant gives the operation, whatever the row. */
46
+ has(operation) {
47
+ return this.ability.rulesFor(operation, this.type).length > 0;
48
+ }
49
+ /** Whether a grant for the operation matches this row. */
50
+ allows(operation, row) {
51
+ return this.ability.can(operation, subject(this.type, { ...row }));
52
+ }
53
+ /** A lookup by slug is answered by the read grants and the by-slug ones. */
54
+ allowsLookup(row) {
55
+ return this.allows('read', row) || this.ability.can('lookup', subject(this.type, { ...row }));
56
+ }
57
+ permittedFields(operation, row) {
58
+ const fields = permittedFieldsOf(this.ability, operation, subject(this.type, { ...row }), {
59
+ fieldsFrom: rule => rule.fields ?? [ORDINARY]
60
+ });
61
+ return { ordinary: fields.includes(ORDINARY), listed: new Set(fields.filter(f => f !== ORDINARY)) };
62
+ }
63
+ }
64
+ //# sourceMappingURL=ability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ability.js","sourceRoot":"","sources":["../../../src/core/access/ability.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,OAAO,EAA6D,MAAM,eAAe,CAA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AC;SAC9C,CAAC,CAAC;QACH,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC;IACtG,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The `can` builder a type's access function calls to grant operations. It
3
+ * records plain grants (`Grant`) and nothing else, so no type exposes the engine
4
+ * under it; ability.ts turns the grants into the engine's rules.
5
+ *
6
+ * access(principal, { can }) {
7
+ * can('read', { where: { status: 'published' } });
8
+ * if (principal.kind === 'composer') can(['update', 'delete'], { where: { owner_id: principal.ownerId } });
9
+ * }
10
+ */
11
+ import { type Operation } from '../errors.ts';
12
+ import { type Where } from './where.ts';
13
+ export declare const OPERATIONS: readonly Operation[];
14
+ export interface GrantOptions {
15
+ /** Confines the grant to rows that match. Absent means every row of the type. */
16
+ where?: Where;
17
+ /**
18
+ * The fields the grant lets the caller write (create and update), by name. Absent means every field that is not
19
+ * a system field. A system field, `owner_id`, `slug`, `parent_id` or `sort_key` is writable only when listed here.
20
+ */
21
+ fields?: readonly string[];
22
+ /**
23
+ * Read only: the grant applies to a lookup by slug and not to a list or a get by id, so a type can let a caller
24
+ * read an entry whose slug it knows without letting it list that entry.
25
+ */
26
+ bySlug?: boolean;
27
+ }
28
+ /** One grant, as recorded; also what `cms.access.rulesFor` hands a page. */
29
+ export interface Grant {
30
+ operation: Operation;
31
+ where?: Where;
32
+ fields?: string[];
33
+ bySlug?: boolean;
34
+ }
35
+ export type Can = (operation: Operation | readonly Operation[], options?: GrantOptions) => void;
36
+ export interface AccessContext {
37
+ can: Can;
38
+ }
39
+ export type AccessFn<P = unknown> = (principal: P, context: AccessContext) => void;
40
+ export declare function runAccess<P>(access: AccessFn<P>, principal: P): Grant[];
41
+ //# sourceMappingURL=can.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"can.d.ts","sourceRoot":"","sources":["../../../src/core/access/can.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnD,eAAO,MAAM,UAAU,EAAE,SAAS,SAAS,EAAsD,CAAC;AAElG,MAAM,WAAW,YAAY;IAC3B,iFAAiF;IACjF,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,4EAA4E;AAC5E,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;AAEhG,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,GAAG,CAAC;CACV;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;AAEnF,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,KAAK,EAAE,CAmBvE"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The `can` builder a type's access function calls to grant operations. It
3
+ * records plain grants (`Grant`) and nothing else, so no type exposes the engine
4
+ * under it; ability.ts turns the grants into the engine's rules.
5
+ *
6
+ * access(principal, { can }) {
7
+ * can('read', { where: { status: 'published' } });
8
+ * if (principal.kind === 'composer') can(['update', 'delete'], { where: { owner_id: principal.ownerId } });
9
+ * }
10
+ */
11
+ import { ConditionError } from "../errors.js";
12
+ import { walkWhere } from "./where.js";
13
+ export const OPERATIONS = ['create', 'read', 'update', 'delete', 'publish'];
14
+ export function runAccess(access, principal) {
15
+ const grants = [];
16
+ const can = (operation, options = {}) => {
17
+ const operations = Array.isArray(operation) ? operation : [operation];
18
+ if (operations.length === 0)
19
+ throw new ConditionError('`can` needs at least one operation.');
20
+ for (const op of operations) {
21
+ if (!OPERATIONS.includes(op))
22
+ throw new ConditionError(`Unknown operation "${String(op)}".`);
23
+ if (options.bySlug && op !== 'read')
24
+ throw new ConditionError('`bySlug` applies to read only.');
25
+ if (options.where !== undefined)
26
+ walkWhere(options.where, () => { });
27
+ grants.push({
28
+ operation: op,
29
+ ...(options.where === undefined ? {} : { where: options.where }),
30
+ ...(options.fields === undefined ? {} : { fields: [...options.fields] }),
31
+ ...(options.bySlug ? { bySlug: true } : {})
32
+ });
33
+ }
34
+ };
35
+ access(principal, { can });
36
+ return grants;
37
+ }
38
+ //# sourceMappingURL=can.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"can.js","sourceRoot":"","sources":["../../../src/core/access/can.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAc,MAAM,YAAY,CAAC;AAEnD,MAAM,CAAC,MAAM,UAAU,GAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAiClG,MAAM,UAAU,SAAS,CAAI,MAAmB,EAAE,SAAY;IAC5D,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE;QAC3C,MAAM,UA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
@@ -0,0 +1,12 @@
1
+ import { isBuiltin, type Where } from './where.ts';
2
+ export interface Sql {
3
+ sql: string;
4
+ params: (string | number)[];
5
+ }
6
+ /** The SQL expression a field is read from, or null when a condition may not name it. */
7
+ export type ColumnOf = (field: string) => string | null;
8
+ export declare function compileWhere(where: Where, columnOf: ColumnOf): Sql;
9
+ /** Grants are alternatives: a row matches when any grant's condition does. No grant, no rows (null). */
10
+ export declare function compileAny(conditions: (Where | undefined)[], columnOf: ColumnOf): Sql | null;
11
+ export { isBuiltin };
12
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/core/access/compile.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAA2C,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAE5F,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7B;AAED,yFAAyF;AACzF,MAAM,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;AAExD,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAQlE;AA4BD,wGAAwG;AACxG,wBAAgB,UAAU,CAAC,UAAU,EAAE,CAAC,KAAK,GAAG,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,GAAG,GAAG,IAAI,CAK5F;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The condition compiler: a condition (where.ts) to a parameterised SQL
3
+ * fragment, ANDed by the store into every SELECT, UPDATE and DELETE. Equals,
4
+ * `in` (at most 90 values), `and` and `or`; nothing else is accepted. It
5
+ * touches no table: the store gives it the column a field is read from.
6
+ */
7
+ import { ConditionError } from "../errors.js";
8
+ import { isBuiltin, normaliseScalar, walkWhere } from "./where.js";
9
+ export function compileWhere(where, columnOf) {
10
+ // Validate first, so an unsupported operator is named before any SQL is built.
11
+ walkWhere(where, field => {
12
+ if (columnOf(field) === null) {
13
+ throw new ConditionError(`The condition names "${field}", which is neither a built-in column nor an indexed field.`, field);
14
+ }
15
+ });
16
+ return build(where, columnOf);
17
+ }
18
+ function build(where, columnOf) {
19
+ const keys = Object.keys(where);
20
+ if (keys[0] === 'and' || keys[0] === 'or') {
21
+ const parts = where[keys[0]].map(w => build(w, columnOf));
22
+ return {
23
+ sql: `(${parts.map(p => p.sql).join(keys[0] === 'and' ? ' AND ' : ' OR ')})`,
24
+ params: parts.flatMap(p => p.params)
25
+ };
26
+ }
27
+ const parts = [];
28
+ for (const [field, value] of Object.entries(where)) {
29
+ const column = columnOf(field);
30
+ if (typeof value === 'object') {
31
+ parts.push(value.in.length === 0
32
+ ? { sql: '0', params: [] }
33
+ : { sql: `${column} IN (${value.in.map(() => '?').join(', ')})`, params: value.in.map(normaliseScalar) });
34
+ }
35
+ else {
36
+ parts.push({ sql: `${column} = ?`, params: [normaliseScalar(value)] });
37
+ }
38
+ }
39
+ if (parts.length === 0)
40
+ return { sql: '1', params: [] };
41
+ return { sql: parts.length === 1 ? parts[0].sql : `(${parts.map(p => p.sql).join(' AND ')})`, params: parts.flatMap(p => p.params) };
42
+ }
43
+ /** Grants are alternatives: a row matches when any grant's condition does. No grant, no rows (null). */
44
+ export function compileAny(conditions, columnOf) {
45
+ if (conditions.length === 0)
46
+ return null;
47
+ if (conditions.some(c => c === undefined || Object.keys(c).length === 0))
48
+ return { sql: '1', params: [] };
49
+ const parts = conditions.map(c => compileWhere(c, columnOf));
50
+ return { sql: `(${parts.map(p => p.sql).join(' OR ')})`, params: parts.flatMap(p => p.params) };
51
+ }
52
+ export { isBuiltin };
53
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../src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EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;AACxI,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,UAAU,CAAC,UAAiC,EAAE,QAAkB;IAC9E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC1G,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9D,OAAO,EAAE,GAAG,EAAE,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;AAClG,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The rules in a form a page can use to show or hide controls. `cms.access.rulesFor`
3
+ * packs a caller's grants into plain JSON, and `permits` answers from that JSON
4
+ * alone. It is for display: enforcement is the store's, and the policy test
5
+ * helper checks that the two agree.
6
+ */
7
+ import type { Operation } from '../errors.ts';
8
+ import type { Grant } from './can.ts';
9
+ import { type Where } from './where.ts';
10
+ export interface PackedTypeRules {
11
+ type: string;
12
+ grants: Grant[];
13
+ }
14
+ export type PackedRules = PackedTypeRules[];
15
+ /** Whether a row satisfies a condition; the row holds the built-in columns and the indexed fields. */
16
+ export declare function matches(where: Where, row: Record<string, unknown>): boolean;
17
+ /**
18
+ * Whether the packed rules give the caller the operation on the type: on any row when `row` is left out, on that
19
+ * row otherwise. A slug lookup is `operation: 'lookup'`.
20
+ */
21
+ export declare function permits(rules: PackedRules, type: string, operation: Operation | 'lookup', row?: Record<string, unknown>): boolean;
22
+ /** What a grant lists by name for a row: undefined when no matching grant, the list otherwise. */
23
+ export declare function pack(type: string, grants: readonly Grant[]): PackedTypeRules;
24
+ //# sourceMappingURL=permits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permits.d.ts","sourceRoot":"","sources":["../../../src/core/access/permits.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAgC,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,WAAW,GAAG,eAAe,EAAE,CAAC;AAE5C,sGAAsG;AACtG,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAS3E;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAMjI;AAED,kGAAkG;AAClG,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,eAAe,CAE5E"}
@@ -0,0 +1,29 @@
1
+ import { normaliseScalar } from "./where.js";
2
+ /** Whether a row satisfies a condition; the row holds the built-in columns and the indexed fields. */
3
+ export function matches(where, row) {
4
+ const keys = Object.keys(where);
5
+ if (keys[0] === 'and')
6
+ return where.and.every(w => matches(w, row));
7
+ if (keys[0] === 'or')
8
+ return where.or.some(w => matches(w, row));
9
+ return Object.entries(where).every(([field, value]) => {
10
+ const actual = row[field];
11
+ if (typeof value === 'object')
12
+ return value.in.some(v => normaliseScalar(v) === actual);
13
+ return normaliseScalar(value) === actual;
14
+ });
15
+ }
16
+ /**
17
+ * Whether the packed rules give the caller the operation on the type: on any row when `row` is left out, on that
18
+ * row otherwise. A slug lookup is `operation: 'lookup'`.
19
+ */
20
+ export function permits(rules, type, operation, row) {
21
+ const grants = rules.find(r => r.type === type)?.grants ?? [];
22
+ const wanted = grants.filter(g => operation === 'lookup' ? g.operation === 'read' : g.operation === operation && !g.bySlug);
23
+ return wanted.some(g => row === undefined || g.where === undefined || matches(g.where, row));
24
+ }
25
+ /** What a grant lists by name for a row: undefined when no matching grant, the list otherwise. */
26
+ export function pack(type, grants) {
27
+ return { type, grants: JSON.parse(JSON.stringify(grants)) };
28
+ }
29
+ //# sourceMappingURL=permits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permits.js","sourceRoot":"","sources":["../../../src/core/access/permits.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAA2B,MAAM,YAAY,CAAC;AAStE,sGAAsG;AACtG,MAAM,UAAU,OAAO,CAAC,KAAY,EAAE,GAA4B;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK;QAAE,OAAQ,KAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1F,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;QAAE,OAAQ,KAAyB,CAAC,EAAE,CAAC,IAAI,C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,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAY,EAAE,CAAC;AACzE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { When } from '../store/types.ts';
2
+ import type { Sql } from './compile.ts';
3
+ /** The SQL expression a field is read from, or null when the type has no such field. */
4
+ export type ReadField = (field: string) => string | null;
5
+ export declare function compileWhen(when: When, read: ReadField): Sql;
6
+ //# sourceMappingURL=when.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../../src/core/access/when.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAExC,wFAAwF;AACxF,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;AAEzD,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,GAAG,CA4C5D"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The precondition of a conditional update: equals, less than, greater than and
3
+ * is-null on a named field, combined with `or` (fields of one object are ANDed).
4
+ * Compiled to SQL and run in the same statement as the write, so it holds at the
5
+ * moment of writing.
6
+ */
7
+ import { ConditionError } from "../errors.js";
8
+ import { isBuiltin } from "./where.js";
9
+ export function compileWhen(when, read) {
10
+ if (typeof when !== 'object' || when === null || Array.isArray(when))
11
+ throw new ConditionError('A precondition is an object.');
12
+ const keys = Object.keys(when);
13
+ if (keys.length === 0)
14
+ throw new ConditionError('A precondition names at least one field.');
15
+ if (keys.includes('or')) {
16
+ if (keys.length !== 1)
17
+ throw new ConditionError('`or` stands alone in a precondition; nest the other fields inside.');
18
+ const list = when.or;
19
+ if (!Array.isArray(list) || list.length === 0)
20
+ throw new ConditionError('`or` takes a list of one or more preconditions.');
21
+ const parts = list.map(w => compileWhen(w, read));
22
+ return { sql: `(${parts.map(p => p.sql).join(' OR ')})`, params: parts.flatMap(p => p.params) };
23
+ }
24
+ const parts = [];
25
+ for (const [field, compare] of Object.entries(when)) {
26
+ const column = read(field);
27
+ if (column === null) {
28
+ throw new ConditionError(`The precondition names "${field}", which is neither a built-in column nor a field of the type.`, field);
29
+ }
30
+ if (typeof compare !== 'object' || compare === null || Array.isArray(compare) || Object.keys(compare).length !== 1) {
31
+ throw new ConditionError(`The precondition on "${field}" is one of equals, lt, gt or isNull.`, field);
32
+ }
33
+ const [op, value] = Object.entries(compare)[0];
34
+ switch (op) {
35
+ case 'equals': {
36
+ if (typeof value === 'boolean')
37
+ parts.push({ sql: `${column} = ?`, params: [value ? 1 : 0] });
38
+ else if (typeof value === 'string' || (typeof value === 'number' && Number.isFinite(value))) {
39
+ if (isBuiltin(field) && typeof value !== 'string')
40
+ throw new ConditionError(`The precondition on "${field}" must compare with a string.`, field);
41
+ parts.push({ sql: `${column} = ?`, params: [value] });
42
+ }
43
+ else
44
+ throw new ConditionError(`The precondition on "${field}" compares with a string, number or boolean; use isNull for null.`, field);
45
+ break;
46
+ }
47
+ case 'lt':
48
+ case 'gt':
49
+ if (typeof value !== 'number' || !Number.isFinite(value))
50
+ throw new ConditionError(`The precondition on "${field}" compares with a number.`, field);
51
+ parts.push({ sql: `${column} ${op === 'lt' ? '<' : '>'} ?`, params: [value] });
52
+ break;
53
+ case 'isNull':
54
+ if (typeof value !== 'boolean')
55
+ throw new ConditionError(`isNull on "${field}" takes true or false.`, field);
56
+ parts.push({ sql: `${column} IS ${value ? '' : 'NOT '}NULL`, params: [] });
57
+ break;
58
+ default:
59
+ throw new ConditionError(`The precondition on "${field}" uses "${op}"; only equals, lt, gt and isNull are supported.`, field);
60
+ }
61
+ }
62
+ return { sql: parts.length === 1 ? parts[0].sql : `(${parts.map(p => p.sql).join(' AND ')})`, params: parts.flatMap(p => p.params) };
63
+ }
64
+ //# sourceMappingURL=when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AC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;AACxI,CAAC"}
@@ -0,0 +1,25 @@
1
+ export type Scalar = string | number | boolean;
2
+ export type Where = {
3
+ and: Where[];
4
+ } | {
5
+ or: Where[];
6
+ } | {
7
+ [field: string]: Scalar | {
8
+ in: Scalar[];
9
+ };
10
+ };
11
+ /** The most values one `in` may hold; D1 allows 100 bound values in a statement. */
12
+ export declare const MAX_IN_VALUES = 90;
13
+ /** The columns every entry has, which a condition may name without declaring them. */
14
+ export declare const BUILTIN_COLUMNS: readonly ["id", "owner_id", "slug", "status", "parent_id", "parent_status"];
15
+ export type BuiltinColumn = (typeof BUILTIN_COLUMNS)[number];
16
+ export declare const isBuiltin: (field: string) => field is BuiltinColumn;
17
+ /** Booleans are stored as 0 and 1 in the column a generated field reads, so both sides use that. */
18
+ export declare const normaliseScalar: (value: Scalar) => string | number;
19
+ /** Walks a condition, calling `onField` for each field it names; throws on anything outside the vocabulary. */
20
+ export declare function walkWhere(where: Where, onField: (field: string, value: Scalar | {
21
+ in: Scalar[];
22
+ }) => void): void;
23
+ /** The condition in the form the ability matches rows with. */
24
+ export declare function toMongo(where: Where): Record<string, unknown>;
25
+ //# sourceMappingURL=where.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"where.d.ts","sourceRoot":"","sources":["../../../src/core/access/where.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE/C,MAAM,MAAM,KAAK,GACb;IAAE,GAAG,EAAE,KAAK,EAAE,CAAA;CAAE,GAChB;IAAE,EAAE,EAAE,KAAK,EAAE,CAAA;CAAE,GACf;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG;QAAE,EAAE,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,CAAC;AAEnD,oFAAoF;AACpF,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,sFAAsF;AACtF,eAAO,MAAM,eAAe,6EAA8E,CAAC;AAC3G,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,KAAK,IAAI,aAAuE,CAAC;AAE3H,oGAAoG;AACpG,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,MAAM,GAAG,MAAgE,CAAC;AAkB1H,+GAA+G;AAC/G,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,EAAE,CAAA;CAAE,KAAK,IAAI,GAAG,IAAI,CAoChH;AAED,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAY7D"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Conditions: the one vocabulary a rule uses to confine a grant to some rows.
3
+ * Equality, membership in a list of at most 90 values, and `and` / `or`. The same
4
+ * condition is compiled to SQL (compile.ts) and handed to the ability for the
5
+ * in-memory answer (ability.ts), so a rule means the same in both.
6
+ */
7
+ import { ConditionError } from "../errors.js";
8
+ /** The most values one `in` may hold; D1 allows 100 bound values in a statement. */
9
+ export const MAX_IN_VALUES = 90;
10
+ /** The columns every entry has, which a condition may name without declaring them. */
11
+ export const BUILTIN_COLUMNS = ['id', 'owner_id', 'slug', 'status', 'parent_id', 'parent_status'];
12
+ export const isBuiltin = (field) => BUILTIN_COLUMNS.includes(field);
13
+ /** Booleans are stored as 0 and 1 in the column a generated field reads, so both sides use that. */
14
+ export const normaliseScalar = (value) => (typeof value === 'boolean' ? (value ? 1 : 0) : value);
15
+ function checkScalar(field, value) {
16
+ if (typeof value === 'string' || typeof value === 'boolean')
17
+ return value;
18
+ if (typeof value === 'number' && Number.isFinite(value))
19
+ return value;
20
+ throw new ConditionError(`The condition on "${field}" compares with ${value === null || value === undefined ? String(value) : typeof value}; use a string, number or boolean.`, field);
21
+ }
22
+ /** What a built-in column holds: text. A number there would be compared as text by SQL and as a number in memory. */
23
+ function checkColumnValue(field, value) {
24
+ if (isBuiltin(field) && typeof value !== 'string') {
25
+ throw new ConditionError(`The condition on "${field}" must compare with a string.`, field);
26
+ }
27
+ }
28
+ /** Walks a condition, calling `onField` for each field it names; throws on anything outside the vocabulary. */
29
+ export function walkWhere(where, onField) {
30
+ if (typeof where !== 'object' || where === null || Array.isArray(where)) {
31
+ throw new ConditionError('A condition is an object.');
32
+ }
33
+ const keys = Object.keys(where);
34
+ if (keys.includes('and') || keys.includes('or')) {
35
+ if (keys.length !== 1)
36
+ throw new ConditionError('`and` and `or` stand alone in a condition; nest the other fields inside.');
37
+ const key = keys[0];
38
+ const list = where[key];
39
+ if (!Array.isArray(list) || list.length === 0) {
40
+ throw new ConditionError(`\`${key}\` takes a list of one or more conditions.`);
41
+ }
42
+ for (const part of list)
43
+ walkWhere(part, onField);
44
+ return;
45
+ }
46
+ for (const field of keys) {
47
+ const value = where[field];
48
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
49
+ const ops = Object.keys(value);
50
+ if (ops.length !== 1 || ops[0] !== 'in' || !Array.isArray(value.in)) {
51
+ throw new ConditionError(`The condition on "${field}" is not supported: only equals and \`in\` are.`, field);
52
+ }
53
+ const list = value.in;
54
+ if (list.length > MAX_IN_VALUES) {
55
+ throw new ConditionError(`The condition on "${field}" lists ${list.length} values; the limit is ${MAX_IN_VALUES}.`, field);
56
+ }
57
+ for (const v of list)
58
+ checkColumnValue(field, checkScalar(field, v));
59
+ onField(field, { in: list });
60
+ }
61
+ else {
62
+ checkColumnValue(field, checkScalar(field, value));
63
+ onField(field, value);
64
+ }
65
+ }
66
+ }
67
+ /** The condition in the form the ability matches rows with. */
68
+ export function toMongo(where) {
69
+ const keys = Object.keys(where);
70
+ if (keys[0] === 'and' || keys[0] === 'or') {
71
+ const list = where[keys[0]];
72
+ return { [keys[0] === 'and' ? '$and' : '$or']: list.map(toMongo) };
73
+ }
74
+ const out = {};
75
+ for (const [field, value] of Object.entries(where)) {
76
+ out[field] =
77
+ typeof value === 'object' ? { $in: value.in.map(normaliseScalar) } : normaliseScalar(value);
78
+ }
79
+ return out;
80
+ }
81
+ //# sourceMappingURL=where.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"where.js","sourceRoot":"","sources":["../../../src/core/access/where.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAS9C,oFAAoF;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAEhC,sFAAsF;AACtF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,CAAU,CAAC;AAE3G,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAA0B,EAAE,CAAE,eAAqC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAE3H,oGAAoG;AACpG,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAmB,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAE1H,SAAS,WAAW,CAAC,KAAa,EAAE,KAAc;IACh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E,EAAE,EAAE,IAAgB,EAAE,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;YACnD,OAAO,CAAC,KAAK,EAAE,KAAe,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,OAAO,CAAC,KAAY;IAClC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAI,KAAiC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC;QAC1D,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;IACrE,CAAC;IACD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAkD,CAAC,EAAE,CAAC;QAChG,GAAG,CAAC,KAAK,CAAC;YACR,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Names of columns of `entries` that more than the SQL layer needs (the migration printer, the startup check). */
2
+ /** The column a generated (indexed) field is read from. */
3
+ export declare const indexedColumn: (field: string) => string;
4
+ /** The built-in columns a migration adds beyond Koguma's, which startup looks for. */
5
+ export declare const ADDED_COLUMNS: readonly ["owner_id", "parent_id", "sort_key", "parent_status"];
6
+ //# sourceMappingURL=columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.d.ts","sourceRoot":"","sources":["../../src/core/columns.ts"],"names":[],"mappings":"AAAA,mHAAmH;AAEnH,2DAA2D;AAC3D,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAAiB,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,aAAa,iEAAkE,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Names of columns of `entries` that more than the SQL layer needs (the migration printer, the startup check). */
2
+ /** The column a generated (indexed) field is read from. */
3
+ export const indexedColumn = (field) => `f_${field}`;
4
+ /** The built-in columns a migration adds beyond Koguma's, which startup looks for. */
5
+ export const ADDED_COLUMNS = ['owner_id', 'parent_id', 'sort_key', 'parent_status'];
6
+ //# sourceMappingURL=columns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.js","sourceRoot":"","sources":["../../src/core/columns.ts"],"names":[],"mappings":"AAAA,mHAAmH;AAEnH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC;AAE7D,sFAAsF;AACtF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,CAAU,CAAC"}