cogens 0.2.0 → 0.2.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.
- package/CHANGELOG.md +21 -0
- package/README.md +14 -5
- package/dist/admin/app.d.ts +21 -0
- package/dist/admin/app.d.ts.map +1 -0
- package/dist/admin/app.js +561 -0
- package/dist/admin/app.js.map +1 -0
- package/dist/admin/assets.d.ts +17 -0
- package/dist/admin/assets.d.ts.map +1 -0
- package/dist/admin/assets.js +51 -0
- package/dist/admin/assets.js.map +1 -0
- package/dist/admin/fields.d.ts +27 -0
- package/dist/admin/fields.d.ts.map +1 -0
- package/dist/admin/fields.js +128 -0
- package/dist/admin/fields.js.map +1 -0
- package/dist/admin/forms.d.ts +18 -0
- package/dist/admin/forms.d.ts.map +1 -0
- package/dist/admin/forms.js +53 -0
- package/dist/admin/forms.js.map +1 -0
- package/dist/admin/index.d.ts +15 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +13 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/rules.d.ts +24 -0
- package/dist/admin/rules.d.ts.map +1 -0
- package/dist/admin/rules.js +51 -0
- package/dist/admin/rules.js.map +1 -0
- package/dist/admin/types.d.ts +96 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +2 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/admin/views.d.ts +109 -0
- package/dist/admin/views.d.ts.map +1 -0
- package/dist/admin/views.js +202 -0
- package/dist/admin/views.js.map +1 -0
- package/dist/auth/handoff.d.ts +27 -0
- package/dist/auth/handoff.d.ts.map +1 -0
- package/dist/auth/handoff.js +41 -0
- package/dist/auth/handoff.js.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/password.d.ts +48 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/password.js +154 -0
- package/dist/auth/password.js.map +1 -0
- package/dist/auth/principal.d.ts +30 -0
- package/dist/auth/principal.d.ts.map +1 -0
- package/dist/auth/principal.js +30 -0
- package/dist/auth/principal.js.map +1 -0
- package/dist/auth/session.d.ts +68 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +92 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/core/access/ability.d.ts +24 -0
- package/dist/core/access/ability.d.ts.map +1 -0
- package/dist/core/access/ability.js +64 -0
- package/dist/core/access/ability.js.map +1 -0
- package/dist/core/access/can.d.ts +41 -0
- package/dist/core/access/can.d.ts.map +1 -0
- package/dist/core/access/can.js +38 -0
- package/dist/core/access/can.js.map +1 -0
- package/dist/core/access/compile.d.ts +12 -0
- package/dist/core/access/compile.d.ts.map +1 -0
- package/dist/core/access/compile.js +53 -0
- package/dist/core/access/compile.js.map +1 -0
- package/dist/core/access/permits.d.ts +24 -0
- package/dist/core/access/permits.d.ts.map +1 -0
- package/dist/core/access/permits.js +29 -0
- package/dist/core/access/permits.js.map +1 -0
- package/dist/core/access/when.d.ts +6 -0
- package/dist/core/access/when.d.ts.map +1 -0
- package/dist/core/access/when.js +64 -0
- package/dist/core/access/when.js.map +1 -0
- package/dist/core/access/where.d.ts +25 -0
- package/dist/core/access/where.d.ts.map +1 -0
- package/dist/core/access/where.js +81 -0
- package/dist/core/access/where.js.map +1 -0
- package/dist/core/columns.d.ts +6 -0
- package/dist/core/columns.d.ts.map +1 -0
- package/dist/core/columns.js +6 -0
- package/dist/core/columns.js.map +1 -0
- package/dist/core/config/define.d.ts +101 -0
- package/dist/core/config/define.d.ts.map +1 -0
- package/dist/core/config/define.js +97 -0
- package/dist/core/config/define.js.map +1 -0
- package/dist/core/config/field.d.ts +71 -0
- package/dist/core/config/field.d.ts.map +1 -0
- package/dist/core/config/field.js +64 -0
- package/dist/core/config/field.js.map +1 -0
- package/dist/core/errors.d.ts +66 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +94 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +31 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/media/index.d.ts +36 -0
- package/dist/core/media/index.d.ts.map +1 -0
- package/dist/core/media/index.js +99 -0
- package/dist/core/media/index.js.map +1 -0
- package/dist/core/principal.d.ts +28 -0
- package/dist/core/principal.d.ts.map +1 -0
- package/dist/core/principal.js +25 -0
- package/dist/core/principal.js.map +1 -0
- package/dist/core/store/assets.d.ts +3 -0
- package/dist/core/store/assets.d.ts.map +1 -0
- package/dist/core/store/assets.js +3 -0
- package/dist/core/store/assets.js.map +1 -0
- package/dist/core/store/cms.d.ts +53 -0
- package/dist/core/store/cms.d.ts.map +1 -0
- package/dist/core/store/cms.js +154 -0
- package/dist/core/store/cms.js.map +1 -0
- package/dist/core/store/content.d.ts +57 -0
- package/dist/core/store/content.d.ts.map +1 -0
- package/dist/core/store/content.js +455 -0
- package/dist/core/store/content.js.map +1 -0
- package/dist/core/store/sql.d.ts +88 -0
- package/dist/core/store/sql.d.ts.map +1 -0
- package/dist/core/store/sql.js +149 -0
- package/dist/core/store/sql.js.map +1 -0
- package/dist/core/store/types.d.ts +107 -0
- package/dist/core/store/types.d.ts.map +1 -0
- package/dist/core/store/types.js +2 -0
- package/dist/core/store/types.js.map +1 -0
- package/dist/core/testing/index.d.ts +27 -0
- package/dist/core/testing/index.d.ts.map +1 -0
- package/dist/core/testing/index.js +60 -0
- package/dist/core/testing/index.js.map +1 -0
- package/dist/migrations-tool/bin.d.ts +3 -0
- package/dist/migrations-tool/bin.d.ts.map +1 -0
- package/dist/migrations-tool/bin.js +40 -0
- package/dist/migrations-tool/bin.js.map +1 -0
- package/dist/migrations-tool/index.d.ts +16 -0
- package/dist/migrations-tool/index.d.ts.map +1 -0
- package/dist/migrations-tool/index.js +24 -0
- package/dist/migrations-tool/index.js.map +1 -0
- package/dist/testing/db.d.ts +16 -0
- package/dist/testing/db.d.ts.map +1 -0
- package/dist/testing/db.js +43 -0
- package/dist/testing/db.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +33 -11
- package/src/core/config/define.ts +1 -1
- package/src/core/store/cms.ts +1 -1
- package/src/migrations-tool/bin.ts +34 -0
- package/{scripts/print-migration.ts → src/migrations-tool/index.ts} +6 -19
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* field.* builders: the content fields of a type. Each holds its label, its kind
|
|
3
|
+
* for the admin and a JSON Schema (draft 7) for @cfworker/json-schema, which
|
|
4
|
+
* validates without `new Function`, so it runs in a Worker.
|
|
5
|
+
*
|
|
6
|
+
* field.text('Title').required().max(100)
|
|
7
|
+
* field.number('Revision').system()
|
|
8
|
+
*/
|
|
9
|
+
import type { Schema } from '@cfworker/json-schema';
|
|
10
|
+
export type FieldType = 'text' | 'longText' | 'markdown' | 'url' | 'email' | 'boolean' | 'number' | 'date' | 'select' | 'reference' | 'references' | 'files' | 'json';
|
|
11
|
+
export interface FieldMeta {
|
|
12
|
+
label: string;
|
|
13
|
+
fieldType: FieldType;
|
|
14
|
+
required: boolean;
|
|
15
|
+
/** A system field is writable only by a caller whose rule lists it by name. */
|
|
16
|
+
system: boolean;
|
|
17
|
+
refContentType?: string;
|
|
18
|
+
options?: string[];
|
|
19
|
+
/** Stored when a create leaves the field out; set by the store, so a system field may have one. */
|
|
20
|
+
default?: unknown;
|
|
21
|
+
}
|
|
22
|
+
/** `T` is the stored value's type and `R` whether the field is required (a phantom, for `Infer`). */
|
|
23
|
+
export declare class FieldBuilder<T = unknown, R extends boolean = false> {
|
|
24
|
+
readonly meta: FieldMeta;
|
|
25
|
+
readonly schema: Schema;
|
|
26
|
+
readonly _type: T;
|
|
27
|
+
readonly _required: R;
|
|
28
|
+
constructor(meta: FieldMeta, schema: Schema);
|
|
29
|
+
/** The value must be present on create (an update may leave it out). */
|
|
30
|
+
required(): FieldBuilder<T, true>;
|
|
31
|
+
/** Writable only by a caller whose rule lists the field by name. */
|
|
32
|
+
system(): FieldBuilder<T, R>;
|
|
33
|
+
/**
|
|
34
|
+
* The value a create stores when the field is left out. The store applies it whoever creates, so a system field
|
|
35
|
+
* the creator may not write (a flag a rule reads, such as `retired: 0`) still starts with a value.
|
|
36
|
+
*/
|
|
37
|
+
default(value: T): FieldBuilder<T, R>;
|
|
38
|
+
/** Maximum length (text), value (number) or count (list). */
|
|
39
|
+
max(value: number): FieldBuilder<T, R>;
|
|
40
|
+
/** Minimum length (text), value (number) or count (list). */
|
|
41
|
+
min(value: number): FieldBuilder<T, R>;
|
|
42
|
+
}
|
|
43
|
+
export interface StoredFile {
|
|
44
|
+
name: string;
|
|
45
|
+
size: number;
|
|
46
|
+
url: string;
|
|
47
|
+
}
|
|
48
|
+
export declare const field: {
|
|
49
|
+
text: (label: string) => FieldBuilder<string, false>;
|
|
50
|
+
longText: (label: string) => FieldBuilder<string, false>;
|
|
51
|
+
/** Markdown, stored as a string. */
|
|
52
|
+
markdown: (label: string) => FieldBuilder<string, false>;
|
|
53
|
+
url: (label: string) => FieldBuilder<string, false>;
|
|
54
|
+
email: (label: string) => FieldBuilder<string, false>;
|
|
55
|
+
boolean: (label: string) => FieldBuilder<boolean, false>;
|
|
56
|
+
number: (label: string) => FieldBuilder<number, false>;
|
|
57
|
+
/** An ISO 8601 date and time. */
|
|
58
|
+
date: (label: string) => FieldBuilder<string, false>;
|
|
59
|
+
select: <const O extends readonly string[]>(label: string, opts: {
|
|
60
|
+
options: O;
|
|
61
|
+
}) => FieldBuilder<O[number], false>;
|
|
62
|
+
/** The id of an entry of another type. */
|
|
63
|
+
ref: (contentType: string, label: string) => FieldBuilder<string, false>;
|
|
64
|
+
/** Ids of entries of another type, in order. */
|
|
65
|
+
refs: (contentType: string, label: string) => FieldBuilder<string[], false>;
|
|
66
|
+
/** A read-only list of stored files, `{ name, size, url }` each. */
|
|
67
|
+
files: (label: string) => FieldBuilder<StoredFile[], false>;
|
|
68
|
+
/** Any JSON value. */
|
|
69
|
+
json: <T = unknown>(label: string) => FieldBuilder<T, false>;
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/core/config/field.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,UAAU,GACV,UAAU,GACV,KAAK,GACL,OAAO,GACP,SAAS,GACT,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,OAAO,GACP,MAAM,CAAC;AAEX,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,+EAA+E;IAC/E,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,mGAAmG;IACnG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qGAAqG;AACrG,qBAAa,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,OAAO,GAAG,KAAK;IAK5D,QAAQ,CAAC,IAAI,EAAE,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM;IALzB,SAAiB,KAAK,EAAE,CAAC,CAAC;IAC1B,SAAiB,SAAS,EAAE,CAAC,CAAC;gBAGnB,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM;IAGzB,wEAAwE;IACxE,QAAQ,IAAI,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC;IAIjC,oEAAoE;IACpE,MAAM,IAAI,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAI5B;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAIrC,6DAA6D;IAC7D,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAKtC,6DAA6D;IAC7D,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;CAIvC;AAKD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,KAAK;kBACF,MAAM;sBACF,MAAM;IACxB,oCAAoC;sBAClB,MAAM;iBACX,MAAM;mBACJ,MAAM;qBACJ,MAAM;oBACP,MAAM;IACtB,iCAAiC;kBACnB,MAAM;mBACL,CAAC,SAAS,SAAS,MAAM,EAAE,SAAS,MAAM,QAAQ;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE;IAE/E,0CAA0C;uBACvB,MAAM,SAAS,MAAM;IAExC,gDAAgD;wBAC5B,MAAM,SAAS,MAAM;IAEzC,oEAAoE;mBACrD,MAAM;IASrB,sBAAsB;WACf,CAAC,mBAAmB,MAAM;CAClC,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** `T` is the stored value's type and `R` whether the field is required (a phantom, for `Infer`). */
|
|
2
|
+
export class FieldBuilder {
|
|
3
|
+
meta;
|
|
4
|
+
schema;
|
|
5
|
+
constructor(meta, schema) {
|
|
6
|
+
this.meta = meta;
|
|
7
|
+
this.schema = schema;
|
|
8
|
+
}
|
|
9
|
+
/** The value must be present on create (an update may leave it out). */
|
|
10
|
+
required() {
|
|
11
|
+
return new FieldBuilder({ ...this.meta, required: true }, this.schema);
|
|
12
|
+
}
|
|
13
|
+
/** Writable only by a caller whose rule lists the field by name. */
|
|
14
|
+
system() {
|
|
15
|
+
return new FieldBuilder({ ...this.meta, system: true }, this.schema);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The value a create stores when the field is left out. The store applies it whoever creates, so a system field
|
|
19
|
+
* the creator may not write (a flag a rule reads, such as `retired: 0`) still starts with a value.
|
|
20
|
+
*/
|
|
21
|
+
default(value) {
|
|
22
|
+
return new FieldBuilder({ ...this.meta, default: value }, this.schema);
|
|
23
|
+
}
|
|
24
|
+
/** Maximum length (text), value (number) or count (list). */
|
|
25
|
+
max(value) {
|
|
26
|
+
const key = this.schema.type === 'string' ? 'maxLength' : this.schema.type === 'number' ? 'maximum' : 'maxItems';
|
|
27
|
+
return new FieldBuilder(this.meta, { ...this.schema, [key]: value });
|
|
28
|
+
}
|
|
29
|
+
/** Minimum length (text), value (number) or count (list). */
|
|
30
|
+
min(value) {
|
|
31
|
+
const key = this.schema.type === 'string' ? 'minLength' : this.schema.type === 'number' ? 'minimum' : 'minItems';
|
|
32
|
+
return new FieldBuilder(this.meta, { ...this.schema, [key]: value });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const make = (label, fieldType, schema, extra = {}) => new FieldBuilder({ label, fieldType, required: false, system: false, ...extra }, schema);
|
|
36
|
+
export const field = {
|
|
37
|
+
text: (label) => make(label, 'text', { type: 'string' }),
|
|
38
|
+
longText: (label) => make(label, 'longText', { type: 'string' }),
|
|
39
|
+
/** Markdown, stored as a string. */
|
|
40
|
+
markdown: (label) => make(label, 'markdown', { type: 'string' }),
|
|
41
|
+
url: (label) => make(label, 'url', { type: 'string', format: 'uri' }),
|
|
42
|
+
email: (label) => make(label, 'email', { type: 'string', format: 'email' }),
|
|
43
|
+
boolean: (label) => make(label, 'boolean', { type: 'boolean' }),
|
|
44
|
+
number: (label) => make(label, 'number', { type: 'number' }),
|
|
45
|
+
/** An ISO 8601 date and time. */
|
|
46
|
+
date: (label) => make(label, 'date', { type: 'string', format: 'date-time' }),
|
|
47
|
+
select: (label, opts) => make(label, 'select', { type: 'string', enum: [...opts.options] }, { options: [...opts.options] }),
|
|
48
|
+
/** The id of an entry of another type. */
|
|
49
|
+
ref: (contentType, label) => make(label, 'reference', { type: 'string' }, { refContentType: contentType }),
|
|
50
|
+
/** Ids of entries of another type, in order. */
|
|
51
|
+
refs: (contentType, label) => make(label, 'references', { type: 'array', items: { type: 'string' } }, { refContentType: contentType }),
|
|
52
|
+
/** A read-only list of stored files, `{ name, size, url }` each. */
|
|
53
|
+
files: (label) => make(label, 'files', {
|
|
54
|
+
type: 'array',
|
|
55
|
+
items: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: { name: { type: 'string' }, size: { type: 'number' }, url: { type: 'string' } },
|
|
58
|
+
required: ['name', 'size', 'url']
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
61
|
+
/** Any JSON value. */
|
|
62
|
+
json: (label) => make(label, 'json', {})
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.js","sourceRoot":"","sources":["../../../src/core/config/field.ts"],"names":[],"mappings":"AAqCA,qGAAqG;AACrG,MAAM,OAAO,YAAY;IAKZ;IACA;IAFX,YACW,IAAe,EACf,MAAc;QADd,SAAI,GAAJ,IAAI,CAAW;QACf,WAAM,GAAN,MAAM,CAAQ;IACtB,CAAC;IAEJ,wEAAwE;IACxE,QAAQ;QACN,OAAO,IAAI,YAAY,CAAU,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAClF,CAAC;IAED,oEAAoE;IACpE,MAAM;QACJ,OAAO,IAAI,YAAY,CAAO,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7E,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KA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O,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/G,0CAA0C;IAC1C,GAAG,EAAE,CAAC,WAAmB,EAAE,KAAa,EAAE,EAAE,CAC1C,IAAI,CAAS,KAAK,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;IACvF,gDAAgD;IAChD,IAAI,EAAE,CAAC,WAAmB,EAAE,KAAa,EAAE,EAAE,CAC3C,IAAI,CAAW,KAAK,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;IACpH,oEAAoE;IACpE,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE,CACvB,IAAI,CAAe,KAAK,EAAE,OAAO,EAAE;QACjC,IAAI,EAAE,OAAO;QACb,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC3F,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;SAClC;KACF,CAAC;IACJ,sBAAsB;IACtB,IAAI,EAAE,CAAc,KAAa,EAAE,EAAE,CAAC,IAAI,CAAI,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC;CACjE,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** The typed errors the store throws. A read the caller may not make never throws; it answers null or an empty list. */
|
|
2
|
+
export type Operation = 'create' | 'read' | 'update' | 'delete' | 'publish';
|
|
3
|
+
/** A write the caller's rules refuse. `field` is set when a field rule caused it. */
|
|
4
|
+
export declare class Forbidden extends Error {
|
|
5
|
+
readonly operation: Operation | 'unpublish';
|
|
6
|
+
readonly type: string;
|
|
7
|
+
readonly field?: string | undefined;
|
|
8
|
+
readonly name = "Forbidden";
|
|
9
|
+
constructor(operation: Operation | 'unpublish', type: string, field?: string | undefined);
|
|
10
|
+
}
|
|
11
|
+
/** The host's configuration is wrong; the message names the type and, where there is one, the field. */
|
|
12
|
+
export declare class ConfigError extends Error {
|
|
13
|
+
readonly type?: string | undefined;
|
|
14
|
+
readonly field?: string | undefined;
|
|
15
|
+
readonly name = "ConfigError";
|
|
16
|
+
constructor(message: string, type?: string | undefined, field?: string | undefined);
|
|
17
|
+
}
|
|
18
|
+
/** A condition the compiler refuses: an unknown operator, a field that is not indexed, or too many values. */
|
|
19
|
+
export declare class ConditionError extends Error {
|
|
20
|
+
readonly field?: string | undefined;
|
|
21
|
+
readonly name = "ConditionError";
|
|
22
|
+
constructor(message: string, field?: string | undefined);
|
|
23
|
+
}
|
|
24
|
+
/** The data does not fit the type's fields, or names a field the type does not have. */
|
|
25
|
+
export declare class ValidationError extends Error {
|
|
26
|
+
readonly type: string;
|
|
27
|
+
readonly issues: {
|
|
28
|
+
field: string;
|
|
29
|
+
message: string;
|
|
30
|
+
}[];
|
|
31
|
+
readonly name = "ValidationError";
|
|
32
|
+
constructor(type: string, issues: {
|
|
33
|
+
field: string;
|
|
34
|
+
message: string;
|
|
35
|
+
}[]);
|
|
36
|
+
}
|
|
37
|
+
/** A before-write hook refused the write. */
|
|
38
|
+
export declare class WriteRefused extends Error {
|
|
39
|
+
readonly type: string;
|
|
40
|
+
readonly name = "WriteRefused";
|
|
41
|
+
constructor(type: string, message: string);
|
|
42
|
+
}
|
|
43
|
+
/** A unique constraint (the id, or a unique slug) was already taken. */
|
|
44
|
+
export declare class Conflict extends Error {
|
|
45
|
+
readonly type: string;
|
|
46
|
+
readonly field: 'id' | 'slug';
|
|
47
|
+
readonly name = "Conflict";
|
|
48
|
+
constructor(type: string, field: 'id' | 'slug');
|
|
49
|
+
}
|
|
50
|
+
/** Publishing a parent would update more children than one atomic write may. */
|
|
51
|
+
export declare class TooManyChildren extends Error {
|
|
52
|
+
readonly type: string;
|
|
53
|
+
readonly count: number;
|
|
54
|
+
readonly limit: number;
|
|
55
|
+
readonly name = "TooManyChildren";
|
|
56
|
+
constructor(type: string, count: number, limit: number);
|
|
57
|
+
}
|
|
58
|
+
/** A bulk write names more entries than one write may hold. */
|
|
59
|
+
export declare class TooManyEntries extends Error {
|
|
60
|
+
readonly type: string;
|
|
61
|
+
readonly count: number;
|
|
62
|
+
readonly limit: number;
|
|
63
|
+
readonly name = "TooManyEntries";
|
|
64
|
+
constructor(type: string, count: number, limit: number);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,wHAAwH;AAExH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE5E,qFAAqF;AACrF,qBAAa,SAAU,SAAQ,KAAK;IAGhC,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,WAAW;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM;IAJzB,SAAkB,IAAI,eAAe;gBAE1B,SAAS,EAAE,SAAS,GAAG,WAAW,EAClC,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,YAAA;CAQ1B;AAED,wGAAwG;AACxG,qBAAa,WAAY,SAAQ,KAAK;IAIlC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM;IAJzB,SAAkB,IAAI,iBAAiB;gBAErC,OAAO,EAAE,MAAM,EACN,IAAI,CAAC,EAA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KAAK,EAAE,MAAM;CAIzB;AAED,+DAA+D;AAC/D,qBAAa,cAAe,SAAQ,KAAK;IAGrC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM;IAJxB,SAAkB,IAAI,oBAAoB;gBAE/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM;CAIzB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** The typed errors the store throws. A read the caller may not make never throws; it answers null or an empty list. */
|
|
2
|
+
/** A write the caller's rules refuse. `field` is set when a field rule caused it. */
|
|
3
|
+
export class Forbidden extends Error {
|
|
4
|
+
operation;
|
|
5
|
+
type;
|
|
6
|
+
field;
|
|
7
|
+
name = 'Forbidden';
|
|
8
|
+
constructor(operation, type, field) {
|
|
9
|
+
super(field === undefined
|
|
10
|
+
? `Forbidden: ${operation} on ${type}.`
|
|
11
|
+
: `Forbidden: ${operation} on ${type} may not write the field "${field}".`);
|
|
12
|
+
this.operation = operation;
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.field = field;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** The host's configuration is wrong; the message names the type and, where there is one, the field. */
|
|
18
|
+
export class ConfigError extends Error {
|
|
19
|
+
type;
|
|
20
|
+
field;
|
|
21
|
+
name = 'ConfigError';
|
|
22
|
+
constructor(message, type, field) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.type = type;
|
|
25
|
+
this.field = field;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** A condition the compiler refuses: an unknown operator, a field that is not indexed, or too many values. */
|
|
29
|
+
export class ConditionError extends Error {
|
|
30
|
+
field;
|
|
31
|
+
name = 'ConditionError';
|
|
32
|
+
constructor(message, field) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.field = field;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** The data does not fit the type's fields, or names a field the type does not have. */
|
|
38
|
+
export class ValidationError extends Error {
|
|
39
|
+
type;
|
|
40
|
+
issues;
|
|
41
|
+
name = 'ValidationError';
|
|
42
|
+
constructor(type, issues) {
|
|
43
|
+
super(`Invalid ${type}: ${issues.map(i => `${i.field}: ${i.message}`).join('; ')}`);
|
|
44
|
+
this.type = type;
|
|
45
|
+
this.issues = issues;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** A before-write hook refused the write. */
|
|
49
|
+
export class WriteRefused extends Error {
|
|
50
|
+
type;
|
|
51
|
+
name = 'WriteRefused';
|
|
52
|
+
constructor(type, message) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.type = type;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** A unique constraint (the id, or a unique slug) was already taken. */
|
|
58
|
+
export class Conflict extends Error {
|
|
59
|
+
type;
|
|
60
|
+
field;
|
|
61
|
+
name = 'Conflict';
|
|
62
|
+
constructor(type, field) {
|
|
63
|
+
super(`Conflict: a ${type} with this ${field} already exists.`);
|
|
64
|
+
this.type = type;
|
|
65
|
+
this.field = field;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Publishing a parent would update more children than one atomic write may. */
|
|
69
|
+
export class TooManyChildren extends Error {
|
|
70
|
+
type;
|
|
71
|
+
count;
|
|
72
|
+
limit;
|
|
73
|
+
name = 'TooManyChildren';
|
|
74
|
+
constructor(type, count, limit) {
|
|
75
|
+
super(`${type} has ${count} children that mirror its status; the limit for one write is ${limit}. Nothing was changed.`);
|
|
76
|
+
this.type = type;
|
|
77
|
+
this.count = count;
|
|
78
|
+
this.limit = limit;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** A bulk write names more entries than one write may hold. */
|
|
82
|
+
export class TooManyEntries extends Error {
|
|
83
|
+
type;
|
|
84
|
+
count;
|
|
85
|
+
limit;
|
|
86
|
+
name = 'TooManyEntries';
|
|
87
|
+
constructor(type, count, limit) {
|
|
88
|
+
super(`${count} ${type} entries in one write; the limit is ${limit}. Nothing was changed.`);
|
|
89
|
+
this.type = type;
|
|
90
|
+
this.count = count;
|
|
91
|
+
this.limit = limit;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,wHAAwH;AAIxH,qFAAqF;AACrF,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGvB;IACA;IACA;IAJO,IAAI,GAAG,WAAW,CAAC;IACrC,YACW,SAAkC,EAClC,IAAY,EACZ,KAAc;QAEvB,KAAK,CACH,KAAK,KAAK,SAAS;YACjB,CAAC,CAAC,cAAc,SAAS,OAAO,IAAI,GAAG;YACvC,CAAC,CAAC,cAAc,SAAS,OAAO,IAAI,6BAA6B,KAAK,IAAI,CAC7E,CAAC;QARO,cAAS,GAAT,SAAS,CAAyB;QAClC,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAS;IAOzB,CAAC;CACF;AAED,wGAAwG;AACxG,MAAM,OAAO,WAAY,SAAQ,KAAK;IAIzB;IACA;IAJO,IAAI,GAAG,aAAa,CAAC;IACvC,YACE,OAAe,EACN,IAAa,EACb,KAAc;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAS;QACb,UAAK,GAAL,KAAK,CAAS;IAGzB,CAAC;CACF;AAED,8GAA8G;AAC9G,MAAM,OAAO,cAAe,SAAQ,KAAK;IAI5B;IAHO,IAAI,GAAG,gBAAgB,CAAC;IAC1C,YACE,OAAe,EACN,KAAc;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,UAAK,GAAL,KAAK,CAAS;IAGzB,CAAC;CACF;AAED,wFAAwF;AACxF,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAG7B;IACA;IAHO,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gB,CAAC;IAC1C,YACW,IAAY,EACZ,KAAa,EACb,KAAa;QAEtB,KAAK,CAAC,GAAG,KAAK,IAAI,IAAI,uCAAuC,KAAK,wBAAwB,CAAC,CAAC;QAJnF,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;QACb,UAAK,GAAL,KAAK,CAAQ;IAGxB,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cogens: the content store. A content type declares who owns it and who may
|
|
3
|
+
* create, read, update, delete and publish it; every read and write names its
|
|
4
|
+
* caller (`cms.content.as(principal)`), and a read the caller may not make
|
|
5
|
+
* answers as a missing row.
|
|
6
|
+
*
|
|
7
|
+
* Imports nothing of the host's, and nothing but `hono`, `@casl/ability` and
|
|
8
|
+
* `@cfworker/json-schema` (test/boundary.test.ts). No export names a
|
|
9
|
+
* type of the decision engine under `can`.
|
|
10
|
+
*/
|
|
11
|
+
export { contentType, defineConfig, group, RESERVED_FIELD_NAMES } from './config/define.ts';
|
|
12
|
+
export type { CmsConfig, ContentType, ContentTypeOptions, Fields, GroupConfig, Infer, ServiceAction, ServiceConfig } from './config/define.ts';
|
|
13
|
+
export { field, FieldBuilder } from './config/field.ts';
|
|
14
|
+
export type { FieldMeta, FieldType, StoredFile } from './config/field.ts';
|
|
15
|
+
export { OPERATIONS } from './access/can.ts';
|
|
16
|
+
export type { AccessContext, AccessFn, Can, Grant, GrantOptions } from './access/can.ts';
|
|
17
|
+
export { MAX_IN_VALUES } from './access/where.ts';
|
|
18
|
+
export type { Scalar, Where } from './access/where.ts';
|
|
19
|
+
export { permits } from './access/permits.ts';
|
|
20
|
+
export type { PackedRules, PackedTypeRules } from './access/permits.ts';
|
|
21
|
+
export { admin, anonymous, system } from './principal.ts';
|
|
22
|
+
export type { AdminPrincipal, AnonymousPrincipal, HostPrincipal, Principal, SystemPrincipal } from './principal.ts';
|
|
23
|
+
export { createCms } from './store/cms.ts';
|
|
24
|
+
export type { Cms, CmsOptions } from './store/cms.ts';
|
|
25
|
+
export type { AfterWriteContext, Compare, ContentApi, CreateInput, Entry, ListOptions, OrderBy, Status, TypeRef, UpdateEachChange, UpdatePatch, UpdateResult, When, WriteContext, WriteOptions } from './store/types.ts';
|
|
26
|
+
export type { Asset, MediaApi, MediaOptions, UploadInput } from './media/index.ts';
|
|
27
|
+
export { ConditionError, ConfigError, Conflict, Forbidden, TooManyChildren, TooManyEntries, ValidationError, WriteRefused } from './errors.ts';
|
|
28
|
+
export type { Operation } from './errors.ts';
|
|
29
|
+
export { policyMatrix, PolicyMismatch } from './testing/index.ts';
|
|
30
|
+
export type { PolicyMatrixOptions, Expectation } from './testing/index.ts';
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC5F,YAAY,EACV,SAAS,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,EACrG,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxD,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEpH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EACV,iBAAiB,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAC9I,IAAI,EAAE,YAAY,EAAE,YAAY,EACjC,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,EACL,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EACjH,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cogens: the content store. A content type declares who owns it and who may
|
|
3
|
+
* create, read, update, delete and publish it; every read and write names its
|
|
4
|
+
* caller (`cms.content.as(principal)`), and a read the caller may not make
|
|
5
|
+
* answers as a missing row.
|
|
6
|
+
*
|
|
7
|
+
* Imports nothing of the host's, and nothing but `hono`, `@casl/ability` and
|
|
8
|
+
* `@cfworker/json-schema` (test/boundary.test.ts). No export names a
|
|
9
|
+
* type of the decision engine under `can`.
|
|
10
|
+
*/
|
|
11
|
+
export { contentType, defineConfig, group, RESERVED_FIELD_NAMES } from "./config/define.js";
|
|
12
|
+
export { field, FieldBuilder } from "./config/field.js";
|
|
13
|
+
export { OPERATIONS } from "./access/can.js";
|
|
14
|
+
export { MAX_IN_VALUES } from "./access/where.js";
|
|
15
|
+
export { permits } from "./access/permits.js";
|
|
16
|
+
export { admin, anonymous, system } from "./principal.js";
|
|
17
|
+
export { createCms } from "./store/cms.js";
|
|
18
|
+
export { ConditionError, ConfigError, Conflict, Forbidden, TooManyChildren, TooManyEntries, ValidationError, WriteRefused } from "./errors.js";
|
|
19
|
+
export { policyMatrix, PolicyMismatch } from "./testing/index.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAI5F,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAG9C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,OAAO,EACL,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EACjH,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type AccessFn } from '../access/can.ts';
|
|
2
|
+
import type { HostPrincipal, Principal } from '../principal.ts';
|
|
3
|
+
export interface MediaOptions {
|
|
4
|
+
bucket: R2Bucket;
|
|
5
|
+
/** Who may create, read and delete assets. */
|
|
6
|
+
access: AccessFn<any>;
|
|
7
|
+
/** Largest upload, in bytes; 10 MB when absent. */
|
|
8
|
+
maxBytes?: number;
|
|
9
|
+
newId?: () => string;
|
|
10
|
+
}
|
|
11
|
+
export interface Asset {
|
|
12
|
+
id: string;
|
|
13
|
+
owner_id: string | null;
|
|
14
|
+
name: string;
|
|
15
|
+
content_type: string;
|
|
16
|
+
size: number;
|
|
17
|
+
/** The R2 key the file is stored under. */
|
|
18
|
+
key: string;
|
|
19
|
+
created_at: string;
|
|
20
|
+
}
|
|
21
|
+
export interface UploadInput {
|
|
22
|
+
name: string;
|
|
23
|
+
contentType: string;
|
|
24
|
+
body: ArrayBuffer | Uint8Array | Blob;
|
|
25
|
+
ownerId?: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface MediaApi {
|
|
28
|
+
upload(input: UploadInput): Promise<Asset>;
|
|
29
|
+
list(): Promise<Asset[]>;
|
|
30
|
+
get(id: string): Promise<Asset | null>;
|
|
31
|
+
remove(id: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export declare function createMedia(db: D1Database, options: MediaOptions, ensureReady: () => Promise<void>): {
|
|
34
|
+
as: (principal: Principal<HostPrincipal>) => MediaApi;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/media/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAa,KAAK,QAAQ,EAAE,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KAAG,QAAQ;EA2E3D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media, reduced to upload, list and delete, each through the same access check
|
|
3
|
+
* as an entry: a host passes an `access` function for assets (the operations
|
|
4
|
+
* create, read and delete, conditions over `owner_id` and `id`), and with none a
|
|
5
|
+
* caller can do nothing. Files live in R2; the row holds the name, type and size.
|
|
6
|
+
*/
|
|
7
|
+
import { compileAny } from "../access/compile.js";
|
|
8
|
+
import { RuleSet } from "../access/ability.js";
|
|
9
|
+
import { runAccess } from "../access/can.js";
|
|
10
|
+
import { ConditionError, Forbidden, ValidationError } from "../errors.js";
|
|
11
|
+
import { deleteAsset, insertAsset, selectAssets } from "../store/assets.js";
|
|
12
|
+
const TYPE = 'asset';
|
|
13
|
+
const columnOf = field => (field === 'owner_id' || field === 'id' ? field : null);
|
|
14
|
+
const DEFAULT_MAX = 10 * 1024 * 1024;
|
|
15
|
+
export function createMedia(db, options, ensureReady) {
|
|
16
|
+
const newId = options.newId ?? (() => crypto.randomUUID());
|
|
17
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX;
|
|
18
|
+
/** Assets answer to the same engine, as a type named `asset` with no fields of its own. */
|
|
19
|
+
function as(principal) {
|
|
20
|
+
const rules = new RuleSet(TYPE, runAccess(options.access, principal));
|
|
21
|
+
const condition = (operation) => {
|
|
22
|
+
try {
|
|
23
|
+
const compiled = compileAny(rules.grants.filter(g => g.operation === operation).map(g => g.where), columnOf);
|
|
24
|
+
return compiled && { sql: `(${compiled.sql})`, params: compiled.params };
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof ConditionError)
|
|
28
|
+
throw new ConditionError(`Media: ${error.message}`, error.field);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const toAsset = (row) => ({
|
|
33
|
+
id: row.id,
|
|
34
|
+
owner_id: row.owner_id,
|
|
35
|
+
name: String(row.data.name ?? ''),
|
|
36
|
+
content_type: String(row.data.content_type ?? ''),
|
|
37
|
+
size: Number(row.data.size ?? 0),
|
|
38
|
+
key: String(row.data.key ?? ''),
|
|
39
|
+
created_at: row.created_at
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
async upload(input) {
|
|
43
|
+
const ownerId = input.ownerId ?? null;
|
|
44
|
+
if (!rules.allows('create', { owner_id: ownerId }))
|
|
45
|
+
throw new Forbidden('create', TYPE);
|
|
46
|
+
const bytes = input.body instanceof Blob ? await input.body.arrayBuffer() : input.body;
|
|
47
|
+
if (bytes.byteLength > maxBytes) {
|
|
48
|
+
throw new ValidationError(TYPE, [{ field: 'body', message: `is ${bytes.byteLength} bytes; the limit is ${maxBytes}.` }]);
|
|
49
|
+
}
|
|
50
|
+
if (input.name.trim() === '')
|
|
51
|
+
throw new ValidationError(TYPE, [{ field: 'name', message: 'is required.' }]);
|
|
52
|
+
await ensureReady();
|
|
53
|
+
const id = newId();
|
|
54
|
+
const key = `media/${id}`;
|
|
55
|
+
await options.bucket.put(key, bytes, { httpMetadata: { contentType: input.contentType } });
|
|
56
|
+
try {
|
|
57
|
+
await insertAsset(db, {
|
|
58
|
+
id,
|
|
59
|
+
owner_id: ownerId,
|
|
60
|
+
data: { name: input.name, content_type: input.contentType, size: bytes.byteLength, key }
|
|
61
|
+
}).run();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
await options.bucket.delete(key);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
return toAsset((await selectAssets(db, { sql: '1', params: [] }, id))[0]);
|
|
68
|
+
},
|
|
69
|
+
async list() {
|
|
70
|
+
const access = condition('read');
|
|
71
|
+
if (!access)
|
|
72
|
+
return [];
|
|
73
|
+
await ensureReady();
|
|
74
|
+
return (await selectAssets(db, access)).map(toAsset);
|
|
75
|
+
},
|
|
76
|
+
async get(id) {
|
|
77
|
+
const access = condition('read');
|
|
78
|
+
if (!access)
|
|
79
|
+
return null;
|
|
80
|
+
await ensureReady();
|
|
81
|
+
const row = (await selectAssets(db, access, id))[0];
|
|
82
|
+
return row ? toAsset(row) : null;
|
|
83
|
+
},
|
|
84
|
+
async remove(id) {
|
|
85
|
+
const access = condition('delete');
|
|
86
|
+
if (!access)
|
|
87
|
+
throw new Forbidden('delete', TYPE);
|
|
88
|
+
await ensureReady();
|
|
89
|
+
const row = (await selectAssets(db, access, id))[0];
|
|
90
|
+
if (!row)
|
|
91
|
+
throw new Forbidden('delete', TYPE);
|
|
92
|
+
await deleteAsset(db, id, access).run();
|
|
93
|
+
await options.bucket.delete(String(row.data.key ?? `media/${id}`));
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return { as };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/media/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAiB,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAiB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAoC5E,MAAM,IAAI,GAAG,OAAO,CAAC;AACrB,MAAM,QAAQ,GAAa,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC5F,MAAM,WAAW,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAErC,MAAM,UAAU,WAAW,CAAC,EAAc,EAAE,OAAqB,EAAE,WAAgC;IACj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AE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpD,OAAO,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACnC,CAAC;YAED,KAAK,CAAC,MAAM,CAAC,EAAE;gBACb,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;gBACnC,IAAI,CAAC,MAAM;oBAAE,MAAM,IAAI,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACjD,MAAM,WAAW,EAAE,CAAC;gBACpB,MAAM,GAAG,GAAG,CAAC,MAAM,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpD,IAAI,CAAC,GAAG;oBAAE,MAAM,IAAI,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAC9C,MAAM,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;gBACxC,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;YACrE,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caller. The host decides who is calling and passes a principal; the store
|
|
3
|
+
* never reads a cookie or a header. Three kinds are built in, and a host adds
|
|
4
|
+
* its own through the type parameter, with whatever claims its rules use.
|
|
5
|
+
*/
|
|
6
|
+
export interface HostPrincipal {
|
|
7
|
+
readonly kind: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AdminPrincipal {
|
|
10
|
+
readonly kind: 'admin';
|
|
11
|
+
/** The operator's id, for the host's own records; the store gives it no meaning. */
|
|
12
|
+
readonly id?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Background work, naming its job. */
|
|
15
|
+
export interface SystemPrincipal {
|
|
16
|
+
readonly kind: 'system';
|
|
17
|
+
readonly job: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AnonymousPrincipal {
|
|
20
|
+
readonly kind: 'anonymous';
|
|
21
|
+
}
|
|
22
|
+
export type Principal<H extends HostPrincipal = never> = AdminPrincipal | SystemPrincipal | AnonymousPrincipal | H;
|
|
23
|
+
export declare const anonymous: AnonymousPrincipal;
|
|
24
|
+
export declare function admin(id?: string): AdminPrincipal;
|
|
25
|
+
export declare function system(job: string): SystemPrincipal;
|
|
26
|
+
/** Checks the shape of a principal a host built, so a typo is an error and not an anonymous caller. */
|
|
27
|
+
export declare function assertPrincipal(principal: unknown): asserts principal is HostPrincipal;
|
|
28
|
+
//# sourceMappingURL=principal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principal.d.ts","sourceRoot":"","sources":["../../src/core/principal.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,uCAAuC;AACvC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC5B;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,aAAa,GAAG,KAAK,IAAI,cAAc,GAAG,eAAe,GAAG,kBAAkB,GAAG,CAAC,CAAC;AAEnH,eAAO,MAAM,SAAS,EAAE,kBAAyD,CAAC;AAElF,wBAAgB,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,cAAc,CAEjD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAGnD;AAED,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,aAAa,CAQtF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caller. The host decides who is calling and passes a principal; the store
|
|
3
|
+
* never reads a cookie or a header. Three kinds are built in, and a host adds
|
|
4
|
+
* its own through the type parameter, with whatever claims its rules use.
|
|
5
|
+
*/
|
|
6
|
+
export const anonymous = Object.freeze({ kind: 'anonymous' });
|
|
7
|
+
export function admin(id) {
|
|
8
|
+
return Object.freeze(id === undefined ? { kind: 'admin' } : { kind: 'admin', id });
|
|
9
|
+
}
|
|
10
|
+
export function system(job) {
|
|
11
|
+
if (typeof job !== 'string' || job.trim() === '')
|
|
12
|
+
throw new TypeError('A system principal must name its job.');
|
|
13
|
+
return Object.freeze({ kind: 'system', job });
|
|
14
|
+
}
|
|
15
|
+
/** Checks the shape of a principal a host built, so a typo is an error and not an anonymous caller. */
|
|
16
|
+
export function assertPrincipal(principal) {
|
|
17
|
+
if (typeof principal !== 'object' || principal === null || typeof principal.kind !== 'string') {
|
|
18
|
+
throw new TypeError('A principal is an object with a `kind`.');
|
|
19
|
+
}
|
|
20
|
+
const p = principal;
|
|
21
|
+
if (p.kind === 'system' && (typeof p.job !== 'string' || p.job.trim() === '')) {
|
|
22
|
+
throw new TypeError('A system principal must name its job.');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=principal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../../src/core/principal.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH,MAAM,CAAC,MAAM,SA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E,WAAW,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sourceRoot":"","sources":["../../../src/core/store/assets.ts"],"names":[],"mappings":"AAAA,yHAAyH;AACzH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAiB,MAAM,UAAU,CAAC"}
|