shutro 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +99 -2
- package/dist/audit/index.d.ts +59 -0
- package/dist/audit/index.js +96 -0
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +11 -0
- package/dist/cli/cli.d.ts +10 -0
- package/dist/cli/cli.js +164 -0
- package/dist/cli/config.d.ts +18 -0
- package/dist/cli/config.js +49 -0
- package/dist/cli/errors.d.ts +16 -0
- package/dist/cli/errors.js +23 -0
- package/dist/cli/generate/generate.d.ts +33 -0
- package/dist/cli/generate/generate.js +84 -0
- package/dist/cli/generate/render.d.ts +23 -0
- package/dist/cli/generate/render.js +249 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.js +65 -0
- package/dist/cli/inspect.d.ts +10 -0
- package/dist/cli/inspect.js +82 -0
- package/dist/cli/packages.d.ts +6 -0
- package/dist/cli/packages.js +6 -0
- package/dist/cli/project.d.ts +18 -0
- package/dist/cli/project.js +39 -0
- package/dist/cli/resolve.d.ts +2 -0
- package/dist/cli/resolve.js +28 -0
- package/dist/core/compute/graph.d.ts +52 -0
- package/dist/core/compute/graph.js +162 -0
- package/dist/core/data/data.d.ts +59 -0
- package/dist/core/data/data.js +119 -0
- package/dist/core/data/load.d.ts +37 -0
- package/dist/core/data/load.js +236 -0
- package/dist/core/env/env.d.ts +468 -0
- package/dist/core/env/env.js +916 -0
- package/dist/core/env/identity.d.ts +43 -0
- package/dist/core/env/identity.js +65 -0
- package/dist/core/env/inspector.d.ts +55 -0
- package/dist/core/env/inspector.js +85 -0
- package/dist/core/env/time.d.ts +12 -0
- package/dist/core/env/time.js +38 -0
- package/dist/core/errors.d.ts +256 -0
- package/dist/core/errors.js +360 -0
- package/dist/core/events/events.d.ts +44 -0
- package/dist/core/events/events.js +58 -0
- package/dist/core/events/workers.d.ts +56 -0
- package/dist/core/events/workers.js +155 -0
- package/dist/core/index.d.ts +51 -0
- package/dist/core/index.js +42 -0
- package/dist/core/model/company.d.ts +6 -0
- package/dist/core/model/company.js +31 -0
- package/dist/core/model/faces.d.ts +42 -0
- package/dist/core/model/faces.js +1 -0
- package/dist/core/model/field.d.ts +479 -0
- package/dist/core/model/field.js +461 -0
- package/dist/core/model/generated.d.ts +77 -0
- package/dist/core/model/generated.js +1 -0
- package/dist/core/model/id.d.ts +33 -0
- package/dist/core/model/id.js +4 -0
- package/dist/core/model/model.d.ts +387 -0
- package/dist/core/model/model.js +566 -0
- package/dist/core/model/partition.d.ts +31 -0
- package/dist/core/model/partition.js +71 -0
- package/dist/core/model/related.d.ts +17 -0
- package/dist/core/model/related.js +60 -0
- package/dist/core/model/typed.d.ts +107 -0
- package/dist/core/model/typed.js +46 -0
- package/dist/core/money/currency.d.ts +39 -0
- package/dist/core/money/currency.js +37 -0
- package/dist/core/money/decimal.d.ts +26 -0
- package/dist/core/money/decimal.js +51 -0
- package/dist/core/money/fx.d.ts +68 -0
- package/dist/core/money/fx.js +124 -0
- package/dist/core/money/money.d.ts +84 -0
- package/dist/core/money/money.js +173 -0
- package/dist/core/money/quantity.d.ts +67 -0
- package/dist/core/money/quantity.js +108 -0
- package/dist/core/money/rounding.d.ts +11 -0
- package/dist/core/money/rounding.js +12 -0
- package/dist/core/recordset/aggregate.d.ts +22 -0
- package/dist/core/recordset/aggregate.js +258 -0
- package/dist/core/recordset/audit.d.ts +33 -0
- package/dist/core/recordset/audit.js +262 -0
- package/dist/core/recordset/compute.d.ts +36 -0
- package/dist/core/recordset/compute.js +414 -0
- package/dist/core/recordset/constraints.d.ts +9 -0
- package/dist/core/recordset/constraints.js +61 -0
- package/dist/core/recordset/domain.d.ts +31 -0
- package/dist/core/recordset/domain.js +300 -0
- package/dist/core/recordset/onchange.d.ts +43 -0
- package/dist/core/recordset/onchange.js +240 -0
- package/dist/core/recordset/recordset.d.ts +110 -0
- package/dist/core/recordset/recordset.js +789 -0
- package/dist/core/recordset/relations.d.ts +15 -0
- package/dist/core/recordset/relations.js +13 -0
- package/dist/core/recordset/rls.d.ts +15 -0
- package/dist/core/recordset/rls.js +108 -0
- package/dist/core/recordset/security.d.ts +56 -0
- package/dist/core/recordset/security.js +269 -0
- package/dist/core/recordset/sequences.d.ts +31 -0
- package/dist/core/recordset/sequences.js +154 -0
- package/dist/core/recordset/source.d.ts +9 -0
- package/dist/core/recordset/source.js +19 -0
- package/dist/core/recordset/sqlErrors.d.ts +6 -0
- package/dist/core/recordset/sqlErrors.js +39 -0
- package/dist/core/recordset/transitions.d.ts +10 -0
- package/dist/core/recordset/transitions.js +80 -0
- package/dist/core/recordset/types.d.ts +415 -0
- package/dist/core/recordset/types.js +8 -0
- package/dist/core/recordset/values.d.ts +33 -0
- package/dist/core/recordset/values.js +177 -0
- package/dist/core/recordset/writes.d.ts +42 -0
- package/dist/core/recordset/writes.js +786 -0
- package/dist/core/registry/ddl.d.ts +31 -0
- package/dist/core/registry/ddl.js +174 -0
- package/dist/core/registry/extension.d.ts +94 -0
- package/dist/core/registry/extension.js +90 -0
- package/dist/core/registry/module.d.ts +89 -0
- package/dist/core/registry/module.js +98 -0
- package/dist/core/registry/registry.d.ts +130 -0
- package/dist/core/registry/registry.js +591 -0
- package/dist/core/security/runtime.d.ts +102 -0
- package/dist/core/security/runtime.js +232 -0
- package/dist/driver-pg/driver.d.ts +88 -0
- package/dist/driver-pg/driver.js +177 -0
- package/dist/driver-pg/errors.d.ts +72 -0
- package/dist/driver-pg/errors.js +182 -0
- package/dist/driver-pg/index.d.ts +7 -0
- package/dist/driver-pg/index.js +7 -0
- package/dist/i18n/index.d.ts +25 -0
- package/dist/i18n/index.js +51 -0
- package/dist/migrate/apply.d.ts +78 -0
- package/dist/migrate/apply.js +167 -0
- package/dist/migrate/catalog.d.ts +10 -0
- package/dist/migrate/catalog.js +122 -0
- package/dist/migrate/diff.d.ts +98 -0
- package/dist/migrate/diff.js +160 -0
- package/dist/migrate/errors.d.ts +21 -0
- package/dist/migrate/errors.js +31 -0
- package/dist/migrate/index.d.ts +18 -0
- package/dist/migrate/index.js +18 -0
- package/dist/migrate/render.d.ts +5 -0
- package/dist/migrate/render.js +101 -0
- package/dist/migrate/schema.d.ts +61 -0
- package/dist/migrate/schema.js +233 -0
- package/dist/security/index.d.ts +147 -0
- package/dist/security/index.js +278 -0
- package/dist/sequence/index.d.ts +63 -0
- package/dist/sequence/index.js +106 -0
- package/dist/sql/ast.d.ts +49 -0
- package/dist/sql/ast.js +47 -0
- package/dist/sql/builder/builder.d.ts +215 -0
- package/dist/sql/builder/builder.js +308 -0
- package/dist/sql/builder/expression.d.ts +80 -0
- package/dist/sql/builder/expression.js +126 -0
- package/dist/sql/compile.d.ts +18 -0
- package/dist/sql/compile.js +41 -0
- package/dist/sql/errors.d.ts +13 -0
- package/dist/sql/errors.js +16 -0
- package/dist/sql/index.d.ts +19 -0
- package/dist/sql/index.js +19 -0
- package/dist/sql/tag.d.ts +47 -0
- package/dist/sql/tag.js +123 -0
- package/package.json +82 -4
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { type Field } from '../model/field.js';
|
|
2
|
+
import { type AnyModel, type FieldDescription, type ModelDescription } from '../model/model.js';
|
|
3
|
+
import { type Module, type ModuleBase } from './module.js';
|
|
4
|
+
import { type GroupDefinition, type PermissionDefinition } from '../../security/index.js';
|
|
5
|
+
import type { SequenceDefinition } from '../../sequence/index.js';
|
|
6
|
+
import { type ComputeGraph } from '../compute/graph.js';
|
|
7
|
+
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
8
|
+
type Simplify<T> = {
|
|
9
|
+
[K in keyof T]: T[K];
|
|
10
|
+
} & NonNullable<unknown>;
|
|
11
|
+
type NameOf<X> = X extends {
|
|
12
|
+
readonly name: infer N extends string;
|
|
13
|
+
} ? string extends N ? never : N : never;
|
|
14
|
+
/** Models and extensions keyed by name; several contributions to one name intersect (fields and methods merge). */
|
|
15
|
+
type ByName<X> = UnionToIntersection<X extends unknown ? NameOf<X> extends never ? NonNullable<unknown> : {
|
|
16
|
+
readonly [K in NameOf<X>]: X;
|
|
17
|
+
} : never>;
|
|
18
|
+
/** The schema view of one module: its models and extensions plus those of its dependencies, recursively. */
|
|
19
|
+
export type SchemaOfModule<M> = M extends Module<infer Ms, infer Deps, infer Exts> ? ByName<Ms[number] | Exts[number]> & SchemaOfModules<Deps> : NonNullable<unknown>;
|
|
20
|
+
/** The schema view of several modules. */
|
|
21
|
+
export type SchemaOfModules<Mods> = Mods extends readonly [infer H, ...infer T] ? SchemaOfModule<H> & SchemaOfModules<T> : Mods extends readonly (infer U)[] ? ModuleBase extends U ? NonNullable<unknown> : UnionToIntersection<SchemaOfModule<U>> : NonNullable<unknown>;
|
|
22
|
+
/** One layer of a method: the definition, an override that calls `next`, or a replacement (RFC 0002 §7.4 step 6). */
|
|
23
|
+
export interface MethodLayer {
|
|
24
|
+
readonly module: string;
|
|
25
|
+
readonly kind: 'definition' | 'override' | 'replace';
|
|
26
|
+
}
|
|
27
|
+
/** A model with its extensions applied, and where everything came from. */
|
|
28
|
+
export interface RegisteredModel {
|
|
29
|
+
/** The final model (base definition plus extensions, rebuilt through `defineModel`). */
|
|
30
|
+
readonly model: AnyModel;
|
|
31
|
+
/** The owning module. */
|
|
32
|
+
readonly module: string;
|
|
33
|
+
/** Modules that extended the model, in load order. */
|
|
34
|
+
readonly extensions: readonly string[];
|
|
35
|
+
/** Field key → contributing module. */
|
|
36
|
+
readonly fieldOrigins: Readonly<Record<string, string>>;
|
|
37
|
+
/** Method name → layers, innermost first. */
|
|
38
|
+
readonly methodLayers: Readonly<Record<string, readonly MethodLayer[]>>;
|
|
39
|
+
}
|
|
40
|
+
/** Where a model or field comes from. */
|
|
41
|
+
export interface Origin {
|
|
42
|
+
readonly module: string;
|
|
43
|
+
}
|
|
44
|
+
/** `ModelDescription` plus provenance (RFC 0001 §9, RFC 0002 §9). */
|
|
45
|
+
export interface RegistryModelDescription extends Omit<ModelDescription, 'fields'> {
|
|
46
|
+
readonly origin: Origin;
|
|
47
|
+
readonly extensions: readonly string[];
|
|
48
|
+
readonly fields: Readonly<Record<string, FieldDescription & {
|
|
49
|
+
readonly origin: Origin;
|
|
50
|
+
}>>;
|
|
51
|
+
readonly methodLayers: Readonly<Record<string, readonly MethodLayer[]>>;
|
|
52
|
+
}
|
|
53
|
+
/** The built, frozen registry. `S` is the schema view: model name → model type. */
|
|
54
|
+
export interface Registry<S = unknown> {
|
|
55
|
+
/** Phantom. */
|
|
56
|
+
readonly '~schema'?: S;
|
|
57
|
+
/** Modules in load order. */
|
|
58
|
+
readonly modules: readonly ModuleBase[];
|
|
59
|
+
/** Module names in load order. */
|
|
60
|
+
readonly loadOrder: readonly string[];
|
|
61
|
+
/** Models in load order (owning modules first, then definition order). */
|
|
62
|
+
readonly models: ReadonlyMap<string, RegisteredModel>;
|
|
63
|
+
/** The compute dependency graph (RFC 0008 §9). */
|
|
64
|
+
readonly compute: ComputeGraph;
|
|
65
|
+
/** Document sequences by code (RFC 0012 §7.1). */
|
|
66
|
+
readonly sequences: ReadonlyMap<string, SequenceDefinition>;
|
|
67
|
+
/** External ids the modules' data declares → owning module and model (RFC 0017). */
|
|
68
|
+
readonly externalIds: ReadonlyMap<string, {
|
|
69
|
+
readonly module: string;
|
|
70
|
+
readonly model: string;
|
|
71
|
+
}>;
|
|
72
|
+
/** Security groups and their closure (RFC 0014 §7.1). */
|
|
73
|
+
readonly security: {
|
|
74
|
+
readonly groups: ReadonlyMap<string, GroupDefinition>;
|
|
75
|
+
closure(codes: Iterable<string>): Set<string>;
|
|
76
|
+
/** True when one of `groups` (a closure) is an administrator group (RFC 0014 §7.9). */
|
|
77
|
+
isAdministrator(groups: ReadonlySet<string>): boolean;
|
|
78
|
+
/** Feature permissions by code (RFC 0014 §7.9). */
|
|
79
|
+
readonly permissions: ReadonlyMap<string, PermissionDefinition>;
|
|
80
|
+
/** False only when the registry was built with `security: { enforce: false }`. */
|
|
81
|
+
readonly enforce: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* `'warn'`: ACL and field-group denials are reported through {@link SecurityOptions.onDenied} and allowed
|
|
84
|
+
* (record rules still apply). `'enforce'` otherwise (or `'off'` with `enforce: false`).
|
|
85
|
+
*/
|
|
86
|
+
readonly mode: 'enforce' | 'warn' | 'off';
|
|
87
|
+
/** Reports a denial `'warn'` mode let through; each distinct message once per registry. */
|
|
88
|
+
denied(message: string): void;
|
|
89
|
+
};
|
|
90
|
+
has(name: string): boolean;
|
|
91
|
+
/** @throws {UnknownModelError} */
|
|
92
|
+
get(name: string): RegisteredModel;
|
|
93
|
+
/** @throws {UnknownModelError} */
|
|
94
|
+
describe(name: string): RegistryModelDescription;
|
|
95
|
+
/** The layers of a method, innermost first (`shutro inspect`). @throws {UnknownModelError} */
|
|
96
|
+
explain(model: string, method: string): readonly MethodLayer[];
|
|
97
|
+
}
|
|
98
|
+
/** Options of {@link buildRegistry}. */
|
|
99
|
+
export interface RegistryOptions<Mods extends readonly ModuleBase[]> {
|
|
100
|
+
/** The application's modules; their dependencies are collected transitively. */
|
|
101
|
+
readonly modules: Mods;
|
|
102
|
+
/**
|
|
103
|
+
* Access control (RFC 0014). Enforced by default; `enforce: false` makes every model, record and field accessible
|
|
104
|
+
* to every environment, for prototypes and for tests of other features. Never ship it off.
|
|
105
|
+
*/
|
|
106
|
+
readonly security?: SecurityOptions;
|
|
107
|
+
}
|
|
108
|
+
/** Access-control options of {@link buildRegistry}. */
|
|
109
|
+
export interface SecurityOptions {
|
|
110
|
+
/**
|
|
111
|
+
* `true` (default) enforces ACL, rules and field groups. `'warn'` is for development: a missing grant is reported
|
|
112
|
+
* and allowed, so prototypes run before their `access` declarations are written; it is refused when
|
|
113
|
+
* `NODE_ENV=production`. `false` turns access control off (tests of other features).
|
|
114
|
+
*/
|
|
115
|
+
readonly enforce?: boolean | 'warn';
|
|
116
|
+
/** Where `'warn'` reports go. Defaults to `process.emitWarning` (code `SHUTRO_ACCESS_WOULD_DENY`). */
|
|
117
|
+
readonly onDenied?: (message: string) => void;
|
|
118
|
+
}
|
|
119
|
+
/** The target model of a relation field, else `undefined`. */
|
|
120
|
+
export declare function targetOf(field: Field): string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Builds the registry: collects and orders modules, registers models, applies extensions in load order under the
|
|
123
|
+
* view-safety rules, and runs the checks that need every model: relation targets exist and belong to a declared
|
|
124
|
+
* dependency, one2many inverses point back, `depends` paths resolve.
|
|
125
|
+
*
|
|
126
|
+
* @throws {DuplicateModuleError} {DuplicateModelError} {UnknownModelError} {UndeclaredDependencyError}
|
|
127
|
+
* {InvalidRelationError} {InvalidDependsPathError} {InvalidExtensionError} {ExtensionConflictError}
|
|
128
|
+
*/
|
|
129
|
+
export declare function buildRegistry<const Mods extends readonly ModuleBase[]>(options: RegistryOptions<Mods>): Registry<Simplify<SchemaOfModules<Mods>>>;
|
|
130
|
+
export {};
|