ultimabase 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +4 -2
- package/dist/access.d.ts +62 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +258 -0
- package/dist/adapter-errors.d.ts +43 -0
- package/dist/adapter-errors.d.ts.map +1 -0
- package/dist/adapter-errors.js +72 -0
- package/dist/adapter-json.d.ts +20 -0
- package/dist/adapter-json.d.ts.map +1 -0
- package/dist/adapter-json.js +2 -0
- package/dist/adapter-migrations.d.ts +90 -0
- package/dist/adapter-migrations.d.ts.map +1 -0
- package/dist/adapter-migrations.js +1 -0
- package/dist/adapter.d.ts +333 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +5 -0
- package/dist/aggregate.d.ts +31 -0
- package/dist/aggregate.d.ts.map +1 -0
- package/dist/aggregate.js +99 -0
- package/dist/app-internals.d.ts +10 -0
- package/dist/app-internals.d.ts.map +1 -0
- package/dist/app-internals.js +12 -0
- package/dist/app-options.d.ts +22 -0
- package/dist/app-options.d.ts.map +1 -0
- package/dist/app-options.js +3 -0
- package/dist/cascade.d.ts +47 -0
- package/dist/cascade.d.ts.map +1 -0
- package/dist/cascade.js +209 -0
- package/dist/cli-config.d.ts +6 -0
- package/dist/cli-config.d.ts.map +1 -0
- package/dist/cli-config.js +45 -0
- package/dist/cli-deploy.d.ts +14 -0
- package/dist/cli-deploy.d.ts.map +1 -0
- package/dist/cli-deploy.js +193 -0
- package/dist/cli-main.d.ts +16 -0
- package/dist/cli-main.d.ts.map +1 -0
- package/dist/cli-main.js +151 -0
- package/dist/cli-migrate.d.ts +20 -0
- package/dist/cli-migrate.d.ts.map +1 -0
- package/dist/cli-migrate.js +105 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +4 -0
- package/dist/complete.d.ts +13 -0
- package/dist/complete.d.ts.map +1 -0
- package/dist/complete.js +60 -0
- package/dist/console-logger.d.ts +3 -0
- package/dist/console-logger.d.ts.map +1 -0
- package/dist/console-logger.js +62 -0
- package/dist/create-many.d.ts +7 -0
- package/dist/create-many.d.ts.map +1 -0
- package/dist/create-many.js +88 -0
- package/dist/decimal.d.ts +23 -0
- package/dist/decimal.d.ts.map +1 -0
- package/dist/decimal.js +50 -0
- package/dist/define-app.d.ts +59 -0
- package/dist/define-app.d.ts.map +1 -0
- package/dist/define-app.js +5 -0
- package/dist/define-enum.d.ts +6 -0
- package/dist/define-enum.d.ts.map +1 -0
- package/dist/define-enum.js +18 -0
- package/dist/define-function.d.ts +25 -0
- package/dist/define-function.d.ts.map +1 -0
- package/dist/define-function.js +111 -0
- package/dist/define-model.d.ts +48 -0
- package/dist/define-model.d.ts.map +1 -0
- package/dist/define-model.js +85 -0
- package/dist/definition.d.ts +179 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +165 -0
- package/dist/delete-many.d.ts +13 -0
- package/dist/delete-many.d.ts.map +1 -0
- package/dist/delete-many.js +58 -0
- package/dist/engine.d.ts +16 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +174 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +43 -0
- package/dist/exact.d.ts +20 -0
- package/dist/exact.d.ts.map +1 -0
- package/dist/exact.js +1 -0
- package/dist/feed.d.ts +6 -0
- package/dist/feed.d.ts.map +1 -0
- package/dist/feed.js +33 -0
- package/dist/field-codec.d.ts +11 -0
- package/dist/field-codec.d.ts.map +1 -0
- package/dist/field-codec.js +48 -0
- package/dist/field-rules.d.ts +57 -0
- package/dist/field-rules.d.ts.map +1 -0
- package/dist/field-rules.js +1 -0
- package/dist/field-type.d.ts +51 -0
- package/dist/field-type.d.ts.map +1 -0
- package/dist/field-type.js +106 -0
- package/dist/fields.d.ts +295 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +1 -0
- package/dist/function.d.ts +126 -0
- package/dist/function.d.ts.map +1 -0
- package/dist/function.js +1 -0
- package/dist/functions.d.ts +18 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +99 -0
- package/dist/group-by.d.ts +10 -0
- package/dist/group-by.d.ts.map +1 -0
- package/dist/group-by.js +145 -0
- package/dist/group-having.d.ts +8 -0
- package/dist/group-having.d.ts.map +1 -0
- package/dist/group-having.js +97 -0
- package/dist/hooks.d.ts +41 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +149 -0
- package/dist/hosts.d.ts +3 -0
- package/dist/hosts.d.ts.map +1 -0
- package/dist/hosts.js +8 -0
- package/dist/identify.d.ts +15 -0
- package/dist/identify.d.ts.map +1 -0
- package/dist/identify.js +71 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/internal.d.ts +28 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +39 -0
- package/dist/lifecycle.d.ts +21 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +149 -0
- package/dist/list-update.d.ts +12 -0
- package/dist/list-update.d.ts.map +1 -0
- package/dist/list-update.js +52 -0
- package/dist/live.d.ts +37 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +139 -0
- package/dist/manifest.d.ts +11 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +60 -0
- package/dist/memory-aggregate.d.ts +7 -0
- package/dist/memory-aggregate.d.ts.map +1 -0
- package/dist/memory-aggregate.js +107 -0
- package/dist/memory-conditions.d.ts +8 -0
- package/dist/memory-conditions.d.ts.map +1 -0
- package/dist/memory-conditions.js +82 -0
- package/dist/memory-draft.d.ts +34 -0
- package/dist/memory-draft.d.ts.map +1 -0
- package/dist/memory-draft.js +255 -0
- package/dist/memory-json.d.ts +6 -0
- package/dist/memory-json.d.ts.map +1 -0
- package/dist/memory-json.js +86 -0
- package/dist/memory-read.d.ts +45 -0
- package/dist/memory-read.d.ts.map +1 -0
- package/dist/memory-read.js +244 -0
- package/dist/memory-search.d.ts +16 -0
- package/dist/memory-search.d.ts.map +1 -0
- package/dist/memory-search.js +110 -0
- package/dist/memory-values.d.ts +23 -0
- package/dist/memory-values.d.ts.map +1 -0
- package/dist/memory-values.js +82 -0
- package/dist/memory.d.ts +4 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +157 -0
- package/dist/migrate.d.ts +22 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +131 -0
- package/dist/model.d.ts +239 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +1 -0
- package/dist/nested-write.d.ts +64 -0
- package/dist/nested-write.d.ts.map +1 -0
- package/dist/nested-write.js +274 -0
- package/dist/number-update.d.ts +18 -0
- package/dist/number-update.d.ts.map +1 -0
- package/dist/number-update.js +96 -0
- package/dist/plugin-app.d.ts +48 -0
- package/dist/plugin-app.d.ts.map +1 -0
- package/dist/plugin-app.js +230 -0
- package/dist/plugin-code.d.ts +17 -0
- package/dist/plugin-code.d.ts.map +1 -0
- package/dist/plugin-code.js +125 -0
- package/dist/plugin-use.d.ts +22 -0
- package/dist/plugin-use.d.ts.map +1 -0
- package/dist/plugin-use.js +161 -0
- package/dist/plugin.d.ts +357 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +17 -0
- package/dist/query-aggregate.d.ts +82 -0
- package/dist/query-aggregate.d.ts.map +1 -0
- package/dist/query-aggregate.js +1 -0
- package/dist/query-args.d.ts +41 -0
- package/dist/query-args.d.ts.map +1 -0
- package/dist/query-args.js +263 -0
- package/dist/query-bulk.d.ts +35 -0
- package/dist/query-bulk.d.ts.map +1 -0
- package/dist/query-bulk.js +1 -0
- package/dist/query-conditions.d.ts +9 -0
- package/dist/query-conditions.d.ts.map +1 -0
- package/dist/query-conditions.js +46 -0
- package/dist/query-context.d.ts +32 -0
- package/dist/query-context.d.ts.map +1 -0
- package/dist/query-context.js +55 -0
- package/dist/query-filter.d.ts +46 -0
- package/dist/query-filter.d.ts.map +1 -0
- package/dist/query-filter.js +1 -0
- package/dist/query-group.d.ts +82 -0
- package/dist/query-group.d.ts.map +1 -0
- package/dist/query-group.js +1 -0
- package/dist/query-json.d.ts +9 -0
- package/dist/query-json.d.ts.map +1 -0
- package/dist/query-json.js +66 -0
- package/dist/query-order.d.ts +15 -0
- package/dist/query-order.d.ts.map +1 -0
- package/dist/query-order.js +115 -0
- package/dist/query-project.d.ts +15 -0
- package/dist/query-project.d.ts.map +1 -0
- package/dist/query-project.js +45 -0
- package/dist/query-search.d.ts +24 -0
- package/dist/query-search.d.ts.map +1 -0
- package/dist/query-search.js +2 -0
- package/dist/query-values.d.ts +28 -0
- package/dist/query-values.d.ts.map +1 -0
- package/dist/query-values.js +91 -0
- package/dist/query-where.d.ts +46 -0
- package/dist/query-where.d.ts.map +1 -0
- package/dist/query-where.js +200 -0
- package/dist/query-write.d.ts +14 -0
- package/dist/query-write.d.ts.map +1 -0
- package/dist/query-write.js +260 -0
- package/dist/query.d.ts +254 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +1 -0
- package/dist/record.d.ts +257 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +1 -0
- package/dist/recorder.d.ts +32 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +152 -0
- package/dist/relation-write.d.ts +41 -0
- package/dist/relation-write.d.ts.map +1 -0
- package/dist/relation-write.js +112 -0
- package/dist/relations.d.ts +42 -0
- package/dist/relations.d.ts.map +1 -0
- package/dist/relations.js +119 -0
- package/dist/rules.d.ts +97 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +71 -0
- package/dist/running.d.ts +29 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +39 -0
- package/dist/schema-indexes.d.ts +11 -0
- package/dist/schema-indexes.d.ts.map +1 -0
- package/dist/schema-indexes.js +59 -0
- package/dist/schema-virtuals.d.ts +19 -0
- package/dist/schema-virtuals.d.ts.map +1 -0
- package/dist/schema-virtuals.js +100 -0
- package/dist/schema.d.ts +35 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +267 -0
- package/dist/scope.d.ts +46 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +82 -0
- package/dist/scratch.d.ts +14 -0
- package/dist/scratch.d.ts.map +1 -0
- package/dist/scratch.js +10 -0
- package/dist/serve.d.ts +2 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +4 -0
- package/dist/symbols.d.ts +10 -0
- package/dist/symbols.d.ts.map +1 -0
- package/dist/symbols.js +1 -0
- package/dist/transaction.d.ts +28 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +156 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/update-many.d.ts +7 -0
- package/dist/update-many.d.ts.map +1 -0
- package/dist/update-many.js +182 -0
- package/dist/uuid.d.ts +7 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +48 -0
- package/dist/validation.d.ts +24 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +72 -0
- package/dist/virtual-read.d.ts +9 -0
- package/dist/virtual-read.d.ts.map +1 -0
- package/dist/virtual-read.js +145 -0
- package/dist/virtual.d.ts +142 -0
- package/dist/virtual.d.ts.map +1 -0
- package/dist/virtual.js +1 -0
- package/dist/write-context.d.ts +46 -0
- package/dist/write-context.d.ts.map +1 -0
- package/dist/write-context.js +102 -0
- package/dist/write-data.d.ts +26 -0
- package/dist/write-data.d.ts.map +1 -0
- package/dist/write-data.js +144 -0
- package/dist/write-plan.d.ts +107 -0
- package/dist/write-plan.d.ts.map +1 -0
- package/dist/write-plan.js +170 -0
- package/dist/write-target.d.ts +17 -0
- package/dist/write-target.d.ts.map +1 -0
- package/dist/write-target.js +59 -0
- package/dist/writes.d.ts +23 -0
- package/dist/writes.d.ts.map +1 -0
- package/dist/writes.js +246 -0
- package/dist/writing.d.ts +10 -0
- package/dist/writing.d.ts.map +1 -0
- package/dist/writing.js +66 -0
- package/package.json +42 -3
- package/src/access.ts +329 -0
- package/src/adapter-errors.ts +89 -0
- package/src/adapter-json.ts +21 -0
- package/src/adapter-migrations.ts +98 -0
- package/src/adapter.ts +363 -0
- package/src/aggregate.ts +136 -0
- package/src/app-internals.ts +26 -0
- package/src/app-options.ts +24 -0
- package/src/cascade.ts +297 -0
- package/src/cli-config.ts +45 -0
- package/src/cli-deploy.ts +235 -0
- package/src/cli-main.ts +165 -0
- package/src/cli-migrate.ts +143 -0
- package/src/cli.ts +5 -0
- package/src/complete.ts +73 -0
- package/src/console-logger.ts +87 -0
- package/src/create-many.ts +126 -0
- package/src/decimal.ts +74 -0
- package/src/define-app.ts +108 -0
- package/src/define-enum.ts +26 -0
- package/src/define-function.ts +188 -0
- package/src/define-model.ts +220 -0
- package/src/definition.ts +352 -0
- package/src/delete-many.ts +76 -0
- package/src/engine.ts +281 -0
- package/src/errors.ts +97 -0
- package/src/exact.ts +49 -0
- package/src/feed.ts +39 -0
- package/src/field-codec.ts +72 -0
- package/src/field-rules.ts +77 -0
- package/src/field-type.ts +219 -0
- package/src/fields.ts +383 -0
- package/src/function.ts +143 -0
- package/src/functions.ts +154 -0
- package/src/group-by.ts +186 -0
- package/src/group-having.ts +143 -0
- package/src/hooks.ts +215 -0
- package/src/hosts.ts +11 -0
- package/src/identify.ts +95 -0
- package/src/index.ts +125 -0
- package/src/internal.ts +68 -0
- package/src/lifecycle.ts +214 -0
- package/src/list-update.ts +71 -0
- package/src/live.ts +199 -0
- package/src/manifest.ts +71 -0
- package/src/memory-aggregate.ts +162 -0
- package/src/memory-conditions.ts +88 -0
- package/src/memory-draft.ts +319 -0
- package/src/memory-json.ts +91 -0
- package/src/memory-read.ts +311 -0
- package/src/memory-search.ts +149 -0
- package/src/memory-values.ts +106 -0
- package/src/memory.ts +173 -0
- package/src/migrate.ts +152 -0
- package/src/model.ts +312 -0
- package/src/nested-write.ts +390 -0
- package/src/number-update.ts +142 -0
- package/src/plugin-app.ts +308 -0
- package/src/plugin-code.ts +158 -0
- package/src/plugin-use.ts +217 -0
- package/src/plugin.ts +400 -0
- package/src/query-aggregate.ts +96 -0
- package/src/query-args.ts +375 -0
- package/src/query-bulk.ts +53 -0
- package/src/query-conditions.ts +53 -0
- package/src/query-context.ts +104 -0
- package/src/query-filter.ts +54 -0
- package/src/query-group.ts +137 -0
- package/src/query-json.ts +90 -0
- package/src/query-order.ts +158 -0
- package/src/query-project.ts +73 -0
- package/src/query-search.ts +31 -0
- package/src/query-values.ts +131 -0
- package/src/query-where.ts +318 -0
- package/src/query-write.ts +360 -0
- package/src/query.ts +400 -0
- package/src/record.ts +379 -0
- package/src/recorder.ts +212 -0
- package/src/relation-write.ts +176 -0
- package/src/relations.ts +165 -0
- package/src/rules.ts +188 -0
- package/src/running.ts +62 -0
- package/src/schema-indexes.ts +88 -0
- package/src/schema-virtuals.ts +134 -0
- package/src/schema.ts +367 -0
- package/src/scope.ts +123 -0
- package/src/scratch.ts +28 -0
- package/src/serve.ts +5 -0
- package/src/symbols.ts +11 -0
- package/src/transaction.ts +211 -0
- package/src/types.ts +79 -0
- package/src/update-many.ts +268 -0
- package/src/uuid.ts +51 -0
- package/src/validation.ts +107 -0
- package/src/virtual-read.ts +198 -0
- package/src/virtual.ts +187 -0
- package/src/write-context.ts +170 -0
- package/src/write-data.ts +188 -0
- package/src/write-plan.ts +273 -0
- package/src/write-target.ts +92 -0
- package/src/writes.ts +361 -0
- package/src/writing.ts +93 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PluginCode } from './definition.ts';
|
|
2
|
+
/** The fixed hooks of D-15. */
|
|
3
|
+
export declare const hookNames: readonly ['beforeFind', 'beforeCreate', 'beforeUpdate', 'beforeDelete', 'afterCreate', 'afterUpdate', 'afterDelete', 'afterCreateCommit', 'afterUpdateCommit', 'afterDeleteCommit'];
|
|
4
|
+
/** Checks what a plugin's author wrote; the types refuse the rest. */
|
|
5
|
+
export declare function pluginCode(definition: unknown): PluginCode;
|
|
6
|
+
export type Command = {
|
|
7
|
+
readonly model: string;
|
|
8
|
+
readonly plugin: string;
|
|
9
|
+
readonly command: string;
|
|
10
|
+
};
|
|
11
|
+
/** The command of `plugin` running on `model`, if any (D-89). */
|
|
12
|
+
export declare function commandOf(model: string, plugin: string): string | undefined;
|
|
13
|
+
/** Runs `run` as `plugin`'s command `command` on `model`. */
|
|
14
|
+
export declare function inCommand<R>(command: Command, run: () => R): R;
|
|
15
|
+
/** Runs a hook's body: the queries it makes run outside any command. */
|
|
16
|
+
export declare function outsideCommands<R>(run: () => R): R;
|
|
17
|
+
//# sourceMappingURL=plugin-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-code.d.ts","sourceRoot":"","sources":["../src/plugin-code.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAmB,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAyBlE,+BAA+B;AAC/B,eAAO,MAAM,SAAS,YACrB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,CACV,CAAA;AAgDV,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,CA0C1D;AAED,MAAM,MAAM,OAAO,GAAG;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACxB,CAAA;AAID,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK3E;AAED,6DAA6D;AAC7D,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAE9D;AAED,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAElD"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// A plugin's code at run time (D-57, D-89): what `definePlugin` checks, the
|
|
2
|
+
// APIs it reads once the application starts, and the command it runs in.
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import { nameOf } from './definition.js';
|
|
5
|
+
import { manifestOf } from './manifest.js';
|
|
6
|
+
import { isObject } from './query-where.js';
|
|
7
|
+
import { current } from './running.js';
|
|
8
|
+
function functionAt(holder, key, path) {
|
|
9
|
+
const value = holder[key];
|
|
10
|
+
if (value === undefined || typeof value === 'function')
|
|
11
|
+
return value;
|
|
12
|
+
throw new TypeError(`${path} is a function.`);
|
|
13
|
+
}
|
|
14
|
+
function objectAt(holder, key, path) {
|
|
15
|
+
const value = holder[key];
|
|
16
|
+
if (value === undefined)
|
|
17
|
+
return {};
|
|
18
|
+
if (!isObject(value))
|
|
19
|
+
throw new TypeError(`${path} is an object.`);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
/** The fixed hooks of D-15. */
|
|
23
|
+
export const hookNames = [
|
|
24
|
+
'beforeFind',
|
|
25
|
+
'beforeCreate',
|
|
26
|
+
'beforeUpdate',
|
|
27
|
+
'beforeDelete',
|
|
28
|
+
'afterCreate',
|
|
29
|
+
'afterUpdate',
|
|
30
|
+
'afterDelete',
|
|
31
|
+
'afterCreateCommit',
|
|
32
|
+
'afterUpdateCommit',
|
|
33
|
+
'afterDeleteCommit',
|
|
34
|
+
];
|
|
35
|
+
/** The APIs of `names`, each read from the running application. */
|
|
36
|
+
function apisOf(plugin, names) {
|
|
37
|
+
const plugins = {};
|
|
38
|
+
for (const name of names) {
|
|
39
|
+
Object.defineProperty(plugins, name, {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: () => {
|
|
42
|
+
const app = current();
|
|
43
|
+
if (app === undefined) {
|
|
44
|
+
throw new Error(`${plugin}: plugins.${name} is read once the application starts.`);
|
|
45
|
+
}
|
|
46
|
+
return app.apis.get(name);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return Object.freeze(plugins);
|
|
51
|
+
}
|
|
52
|
+
const isList = (value) => Array.isArray(value);
|
|
53
|
+
/** `addedIndexes`, each `{ fields, unique?, contains? }`; startup checks the fields. */
|
|
54
|
+
function indexesOf(value, path) {
|
|
55
|
+
const indexes = value ?? [];
|
|
56
|
+
const valid = (index) => isObject(index) &&
|
|
57
|
+
isList(index['fields']) &&
|
|
58
|
+
index['fields'].every((field) => typeof field === 'string') &&
|
|
59
|
+
(index['unique'] === undefined || typeof index['unique'] === 'boolean') &&
|
|
60
|
+
(index['contains'] === undefined || index['contains'] === true);
|
|
61
|
+
if (!isList(indexes) || !indexes.every(valid)) {
|
|
62
|
+
throw new TypeError(`${path} is a list of { fields, unique?, contains?: true }.`);
|
|
63
|
+
}
|
|
64
|
+
return Object.freeze(indexes.map(({ fields, unique, contains }) => ({
|
|
65
|
+
fields: [...fields],
|
|
66
|
+
...(unique === undefined ? {} : { unique }),
|
|
67
|
+
...(contains === undefined ? {} : { contains }),
|
|
68
|
+
})));
|
|
69
|
+
}
|
|
70
|
+
/** Checks what a plugin's author wrote; the types refuse the rest. */
|
|
71
|
+
export function pluginCode(definition) {
|
|
72
|
+
if (!isObject(definition))
|
|
73
|
+
throw new TypeError('definePlugin takes an object.');
|
|
74
|
+
const name = nameOf(definition['name'], 'definePlugin');
|
|
75
|
+
const requires = Object.keys(objectAt(definition, 'requires', `${name}.requires`));
|
|
76
|
+
const optional = Object.keys(objectAt(definition, 'optional', `${name}.optional`));
|
|
77
|
+
const given = objectAt(definition, 'hooks', `${name}.hooks`);
|
|
78
|
+
const hooks = {};
|
|
79
|
+
for (const hook of hookNames) {
|
|
80
|
+
hooks[hook] = functionAt(given, hook, `${name}.hooks.${hook}`);
|
|
81
|
+
}
|
|
82
|
+
const redirect = objectAt(definition, 'redirect', `${name}.redirect`);
|
|
83
|
+
const part = (key) => functionAt(definition, key, `${name}.${key}`);
|
|
84
|
+
const models = definition['models'] ?? [];
|
|
85
|
+
if (!isList(models)) {
|
|
86
|
+
throw new TypeError(`${name}.models is an array.`);
|
|
87
|
+
}
|
|
88
|
+
return Object.freeze({
|
|
89
|
+
name,
|
|
90
|
+
manifest: manifestOf(definition['manifest'], name),
|
|
91
|
+
requires,
|
|
92
|
+
optional,
|
|
93
|
+
hooks: Object.freeze(hooks),
|
|
94
|
+
redirect: functionAt(redirect, 'delete', `${name}.redirect.delete`),
|
|
95
|
+
commands: part('commands'),
|
|
96
|
+
api: part('api'),
|
|
97
|
+
addedFields: part('addedFields'),
|
|
98
|
+
addedIndexes: indexesOf(definition['addedIndexes'], `${name}.addedIndexes`),
|
|
99
|
+
start: part('start'),
|
|
100
|
+
stop: part('stop'),
|
|
101
|
+
identify: part('identify'),
|
|
102
|
+
caller: part('caller'),
|
|
103
|
+
changed: part('changed'),
|
|
104
|
+
missed: part('missed'),
|
|
105
|
+
functions: part('functions'),
|
|
106
|
+
models: Object.freeze([...models]),
|
|
107
|
+
plugins: apisOf(name, [...requires, ...optional]),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const commands = new AsyncLocalStorage();
|
|
111
|
+
/** The command of `plugin` running on `model`, if any (D-89). */
|
|
112
|
+
export function commandOf(model, plugin) {
|
|
113
|
+
const running = commands.getStore();
|
|
114
|
+
return running?.model === model && running.plugin === plugin
|
|
115
|
+
? running.command
|
|
116
|
+
: undefined;
|
|
117
|
+
}
|
|
118
|
+
/** Runs `run` as `plugin`'s command `command` on `model`. */
|
|
119
|
+
export function inCommand(command, run) {
|
|
120
|
+
return commands.run(command, run);
|
|
121
|
+
}
|
|
122
|
+
/** Runs a hook's body: the queries it makes run outside any command. */
|
|
123
|
+
export function outsideCommands(run) {
|
|
124
|
+
return commands.exit(run);
|
|
125
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FieldDefinition, IndexDefinition, ModelDefinition, PluginCode, PluginRecord, PluginUse } from './definition.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the fields a `fields` callback, or a plugin's `addedFields`, built.
|
|
4
|
+
* `owners` names the plugin that added each field.
|
|
5
|
+
*/
|
|
6
|
+
export declare function addFields(model: string, built: unknown, fields: Map<string, FieldDefinition>, owners: Map<string, string>, plugin?: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* Reads a model's `use`: each entry once, the fields its plugins add into
|
|
9
|
+
* `fields`, and their commands, built with `queries`.
|
|
10
|
+
*/
|
|
11
|
+
/** The plugin entries `use` lists, each once (D-27). */
|
|
12
|
+
export declare function entriesOf(name: string, use: unknown): readonly PluginRecord[];
|
|
13
|
+
export declare function usedBy(model: string, use: readonly unknown[], fields: Map<string, FieldDefinition>, queries: object): {
|
|
14
|
+
readonly uses: readonly PluginUse[];
|
|
15
|
+
readonly commands: ReadonlyMap<string, unknown>;
|
|
16
|
+
readonly indexes: readonly IndexDefinition[];
|
|
17
|
+
};
|
|
18
|
+
/** Stops startup when `owner` uses a plugin that `plugins` does not hold. */
|
|
19
|
+
export declare function checkInstalled(owner: string, code: PluginCode, plugins: readonly PluginCode[]): void;
|
|
20
|
+
/** A model's plugins in the order of `plugins`, each one installed. */
|
|
21
|
+
export declare function installedUses(definition: ModelDefinition, plugins: readonly PluginCode[]): readonly PluginUse[];
|
|
22
|
+
//# sourceMappingURL=plugin-use.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-use.d.ts","sourceRoot":"","sources":["../src/plugin-use.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,EACV,YAAY,EACZ,SAAS,EACT,MAAM,iBAAiB,CAAA;AAkBxB;;;GAGG;AACH,wBAAgB,SAAS,CACxB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,MAAM,CAAC,EAAE,MAAM,GACb,IAAI,CAyBN;AA0DD;;;GAGG;AACH,wDAAwD;AACxD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,SAAS,YAAY,EAAE,CAc7E;AAED,wBAAgB,MAAM,CACrB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,SAAS,OAAO,EAAE,EACvB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACpC,OAAO,EAAE,MAAM,GACb;IACF,QAAQ,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAA;IACnC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/C,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAA;CAC5C,CAyBA;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,SAAS,UAAU,EAAE,GAC5B,IAAI,CASN;AAED,uEAAuE;AACvE,wBAAgB,aAAa,CAC5B,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,SAAS,UAAU,EAAE,GAC5B,SAAS,SAAS,EAAE,CAmBtB"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { fieldBuilders, fieldDefinitions, pluginEntries } from './definition.js';
|
|
2
|
+
import { inCommand } from './plugin-code.js';
|
|
3
|
+
import { isObject, systemFields } from './query-where.js';
|
|
4
|
+
import { Refused } from './errors.js';
|
|
5
|
+
/** The kernel's names, which a model's field cannot take (D-22, D-20, D-134, D-148). */
|
|
6
|
+
const reserved = new Set([
|
|
7
|
+
...systemFields,
|
|
8
|
+
'AND',
|
|
9
|
+
'OR',
|
|
10
|
+
'NOT',
|
|
11
|
+
'_count',
|
|
12
|
+
'_search',
|
|
13
|
+
'_relevance',
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* Adds the fields a `fields` callback, or a plugin's `addedFields`, built.
|
|
17
|
+
* `owners` names the plugin that added each field.
|
|
18
|
+
*/
|
|
19
|
+
export function addFields(model, built, fields, owners, plugin) {
|
|
20
|
+
if (!isObject(built)) {
|
|
21
|
+
const part = plugin === undefined ? 'fields' : `${plugin}.addedFields`;
|
|
22
|
+
throw new Refused(`${model}: ${part} must return an object of fields.`);
|
|
23
|
+
}
|
|
24
|
+
for (const [field, value] of Object.entries(built)) {
|
|
25
|
+
const recorded = typeof value === 'object' && value !== null
|
|
26
|
+
? fieldDefinitions.get(value)
|
|
27
|
+
: undefined;
|
|
28
|
+
if (recorded === undefined) {
|
|
29
|
+
throw new Refused(`${model}.${field} is not a field a builder returned.`);
|
|
30
|
+
}
|
|
31
|
+
if (reserved.has(field)) {
|
|
32
|
+
throw new Refused(`${model}.${field}: the kernel owns this name.`);
|
|
33
|
+
}
|
|
34
|
+
if (plugin !== undefined && fields.has(field)) {
|
|
35
|
+
const owner = owners.get(field) ?? model;
|
|
36
|
+
throw new Refused(`${model}.${field}: ${plugin} adds a field ${owner} already has.`);
|
|
37
|
+
}
|
|
38
|
+
fields.set(field, recorded);
|
|
39
|
+
if (plugin !== undefined)
|
|
40
|
+
owners.set(field, plugin);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Runs a command's function, or each function of its object, as it. */
|
|
44
|
+
function wrapped(value, command, path) {
|
|
45
|
+
const run = (fn) => (...args) => inCommand(command, () => {
|
|
46
|
+
const result = Reflect.apply(fn, undefined, args);
|
|
47
|
+
return result;
|
|
48
|
+
});
|
|
49
|
+
if (typeof value === 'function')
|
|
50
|
+
return run(value);
|
|
51
|
+
const refused = new TypeError(`${path} is a function or an object of functions.`);
|
|
52
|
+
if (!isObject(value))
|
|
53
|
+
throw refused;
|
|
54
|
+
const functions = {};
|
|
55
|
+
for (const [key, fn] of Object.entries(value)) {
|
|
56
|
+
if (typeof fn !== 'function')
|
|
57
|
+
throw refused;
|
|
58
|
+
functions[key] = run(fn);
|
|
59
|
+
}
|
|
60
|
+
return Object.freeze(functions);
|
|
61
|
+
}
|
|
62
|
+
function commandsOf(model, uses, methods) {
|
|
63
|
+
const commands = new Map();
|
|
64
|
+
const owners = new Map();
|
|
65
|
+
for (const { code, model: given } of uses) {
|
|
66
|
+
if (code.commands === undefined)
|
|
67
|
+
continue;
|
|
68
|
+
const built = Reflect.apply(code.commands, undefined, [given]);
|
|
69
|
+
if (!isObject(built)) {
|
|
70
|
+
throw new TypeError(`${code.name}.commands returns an object.`);
|
|
71
|
+
}
|
|
72
|
+
for (const [command, value] of Object.entries(built)) {
|
|
73
|
+
const path = `${model}.${command}`;
|
|
74
|
+
if (methods.has(command)) {
|
|
75
|
+
throw new Refused(`${path}: ${code.name} adds a command named after a model method.`);
|
|
76
|
+
}
|
|
77
|
+
const other = owners.get(command);
|
|
78
|
+
if (other !== undefined) {
|
|
79
|
+
throw new Refused(`${path}: ${other} and ${code.name} both add this command.`);
|
|
80
|
+
}
|
|
81
|
+
owners.set(command, code.name);
|
|
82
|
+
const running = { model, plugin: code.name, command };
|
|
83
|
+
commands.set(command, wrapped(value, running, path));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return commands;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Reads a model's `use`: each entry once, the fields its plugins add into
|
|
90
|
+
* `fields`, and their commands, built with `queries`.
|
|
91
|
+
*/
|
|
92
|
+
/** The plugin entries `use` lists, each once (D-27). */
|
|
93
|
+
export function entriesOf(name, use) {
|
|
94
|
+
if (!Array.isArray(use))
|
|
95
|
+
throw new Refused(`${name}.use is a list.`);
|
|
96
|
+
const entries = [];
|
|
97
|
+
for (const value of use) {
|
|
98
|
+
const entry = isObject(value) ? pluginEntries.get(value) : undefined;
|
|
99
|
+
if (entry === undefined) {
|
|
100
|
+
throw new Refused(`${name}.use lists a value no plugin's entry returned.`);
|
|
101
|
+
}
|
|
102
|
+
if (entries.some((other) => other.code.name === entry.code.name)) {
|
|
103
|
+
throw new Refused(`${name}.use lists ${entry.code.name} twice.`);
|
|
104
|
+
}
|
|
105
|
+
entries.push(entry);
|
|
106
|
+
}
|
|
107
|
+
return entries;
|
|
108
|
+
}
|
|
109
|
+
export function usedBy(model, use, fields, queries) {
|
|
110
|
+
const uses = [];
|
|
111
|
+
const owners = new Map();
|
|
112
|
+
for (const { code, options } of entriesOf(model, use)) {
|
|
113
|
+
if (code.addedFields !== undefined) {
|
|
114
|
+
const built = Reflect.apply(code.addedFields, undefined, [
|
|
115
|
+
fieldBuilders,
|
|
116
|
+
options,
|
|
117
|
+
]);
|
|
118
|
+
addFields(model, built, fields, owners, code.name);
|
|
119
|
+
}
|
|
120
|
+
const given = { name: model, queries, options, plugins: code.plugins };
|
|
121
|
+
uses.push({ code, model: Object.freeze(given) });
|
|
122
|
+
}
|
|
123
|
+
const redirecting = uses.filter((each) => each.code.redirect !== undefined);
|
|
124
|
+
if (redirecting.length > 1) {
|
|
125
|
+
const names = redirecting.map((each) => each.code.name).join(' and ');
|
|
126
|
+
throw new Refused(`${model}: ${names} both redirect delete.`);
|
|
127
|
+
}
|
|
128
|
+
const methods = new Set(['name', 'with', 'nullable', ...Object.keys(queries)]);
|
|
129
|
+
return {
|
|
130
|
+
uses,
|
|
131
|
+
commands: commandsOf(model, uses, methods),
|
|
132
|
+
indexes: uses.flatMap(({ code }) => code.addedIndexes),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** Stops startup when `owner` uses a plugin that `plugins` does not hold. */
|
|
136
|
+
export function checkInstalled(owner, code, plugins) {
|
|
137
|
+
if (plugins.includes(code))
|
|
138
|
+
return;
|
|
139
|
+
const { name } = code;
|
|
140
|
+
const other = plugins.some((each) => each.name === name);
|
|
141
|
+
throw new Refused(other
|
|
142
|
+
? `${owner} uses a ${name} from another definePlugin than the one in plugins.`
|
|
143
|
+
: `${owner} uses ${name}, which is not in plugins.`);
|
|
144
|
+
}
|
|
145
|
+
/** A model's plugins in the order of `plugins`, each one installed. */
|
|
146
|
+
export function installedUses(definition, plugins) {
|
|
147
|
+
const at = (use) => plugins.indexOf(use.code);
|
|
148
|
+
for (const use of definition.uses) {
|
|
149
|
+
checkInstalled(definition.name, use.code, plugins);
|
|
150
|
+
}
|
|
151
|
+
// A field type's plugin runs its hooks on the model, as if used (D-152).
|
|
152
|
+
const { name, queries } = definition;
|
|
153
|
+
const implicit = plugins
|
|
154
|
+
.filter((code) => !definition.uses.some((use) => use.code === code))
|
|
155
|
+
.filter((code) => [...definition.fields.values()].some((field) => field.kind === 'scalar' && field.codec?.plugin === code.name))
|
|
156
|
+
.map((code) => {
|
|
157
|
+
const model = { name, queries, options: {}, plugins: code.plugins };
|
|
158
|
+
return { code, model: Object.freeze(model) };
|
|
159
|
+
});
|
|
160
|
+
return [...definition.uses, ...implicit].toSorted((a, b) => at(a) - at(b));
|
|
161
|
+
}
|