trama-forms 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/LICENSE +21 -0
- package/README.md +83 -2
- package/dist/core/acceptance.d.ts +15 -0
- package/dist/core/acceptance.js +37 -0
- package/dist/core/address.d.ts +45 -0
- package/dist/core/address.js +68 -0
- package/dist/core/authoring-checks.d.ts +39 -0
- package/dist/core/authoring-checks.js +1 -0
- package/dist/core/authoring-form.d.ts +23 -0
- package/dist/core/authoring-form.js +1 -0
- package/dist/core/authoring-params.d.ts +37 -0
- package/dist/core/authoring-params.js +1 -0
- package/dist/core/authoring-relations.d.ts +46 -0
- package/dist/core/authoring-relations.js +1 -0
- package/dist/core/authoring-rows.d.ts +109 -0
- package/dist/core/authoring-rows.js +1 -0
- package/dist/core/authoring-values.d.ts +36 -0
- package/dist/core/authoring-values.js +1 -0
- package/dist/core/authoring.d.ts +117 -0
- package/dist/core/authoring.js +1 -0
- package/dist/core/baseline.d.ts +12 -0
- package/dist/core/baseline.js +66 -0
- package/dist/core/candidates.d.ts +26 -0
- package/dist/core/candidates.js +155 -0
- package/dist/core/collections.d.ts +59 -0
- package/dist/core/collections.js +138 -0
- package/dist/core/commands.d.ts +15 -0
- package/dist/core/commands.js +64 -0
- package/dist/core/compile.d.ts +18 -0
- package/dist/core/compile.js +60 -0
- package/dist/core/compiled.d.ts +34 -0
- package/dist/core/compiled.js +12 -0
- package/dist/core/config.d.ts +103 -0
- package/dist/core/config.js +1 -0
- package/dist/core/cycles.d.ts +14 -0
- package/dist/core/cycles.js +39 -0
- package/dist/core/data.d.ts +40 -0
- package/dist/core/data.js +236 -0
- package/dist/core/declarations.d.ts +61 -0
- package/dist/core/declarations.js +202 -0
- package/dist/core/definition.d.ts +54 -0
- package/dist/core/definition.js +3 -0
- package/dist/core/derived-fields.d.ts +37 -0
- package/dist/core/derived-fields.js +121 -0
- package/dist/core/derived-scope.d.ts +55 -0
- package/dist/core/derived-scope.js +105 -0
- package/dist/core/derived.d.ts +76 -0
- package/dist/core/derived.js +180 -0
- package/dist/core/endpoints.d.ts +94 -0
- package/dist/core/endpoints.js +95 -0
- package/dist/core/engine-types.d.ts +43 -0
- package/dist/core/engine-types.js +1 -0
- package/dist/core/engine.d.ts +9 -0
- package/dist/core/engine.js +140 -0
- package/dist/core/evaluation.d.ts +20 -0
- package/dist/core/evaluation.js +62 -0
- package/dist/core/external.d.ts +13 -0
- package/dist/core/external.js +49 -0
- package/dist/core/field-definitions.d.ts +103 -0
- package/dist/core/field-definitions.js +20 -0
- package/dist/core/field-traits.d.ts +29 -0
- package/dist/core/field-traits.js +149 -0
- package/dist/core/fields.d.ts +26 -0
- package/dist/core/fields.js +89 -0
- package/dist/core/forms.d.ts +23 -0
- package/dist/core/forms.js +46 -0
- package/dist/core/handles.d.ts +56 -0
- package/dist/core/handles.js +128 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +7 -0
- package/dist/core/invalidation.d.ts +30 -0
- package/dist/core/invalidation.js +161 -0
- package/dist/core/issues.d.ts +22 -0
- package/dist/core/issues.js +60 -0
- package/dist/core/known-keys.d.ts +4 -0
- package/dist/core/known-keys.js +22 -0
- package/dist/core/lists.d.ts +27 -0
- package/dist/core/lists.js +174 -0
- package/dist/core/lock.d.ts +4 -0
- package/dist/core/lock.js +70 -0
- package/dist/core/marking.d.ts +16 -0
- package/dist/core/marking.js +28 -0
- package/dist/core/marks.d.ts +32 -0
- package/dist/core/marks.js +203 -0
- package/dist/core/memory.d.ts +79 -0
- package/dist/core/memory.js +127 -0
- package/dist/core/messages.d.ts +20 -0
- package/dist/core/messages.js +46 -0
- package/dist/core/multiple.d.ts +12 -0
- package/dist/core/multiple.js +123 -0
- package/dist/core/notify.d.ts +32 -0
- package/dist/core/notify.js +160 -0
- package/dist/core/observation.d.ts +7 -0
- package/dist/core/observation.js +80 -0
- package/dist/core/observe.d.ts +19 -0
- package/dist/core/observe.js +59 -0
- package/dist/core/operation.d.ts +8 -0
- package/dist/core/operation.js +48 -0
- package/dist/core/options.d.ts +40 -0
- package/dist/core/options.js +32 -0
- package/dist/core/outputs.d.ts +58 -0
- package/dist/core/outputs.js +149 -0
- package/dist/core/param-memory.d.ts +13 -0
- package/dist/core/param-memory.js +17 -0
- package/dist/core/params.d.ts +37 -0
- package/dist/core/params.js +70 -0
- package/dist/core/pass.d.ts +6 -0
- package/dist/core/pass.js +141 -0
- package/dist/core/patches.d.ts +15 -0
- package/dist/core/patches.js +106 -0
- package/dist/core/prepare.d.ts +19 -0
- package/dist/core/prepare.js +105 -0
- package/dist/core/prepared.d.ts +10 -0
- package/dist/core/prepared.js +14 -0
- package/dist/core/program.d.ts +43 -0
- package/dist/core/program.js +100 -0
- package/dist/core/publication.d.ts +20 -0
- package/dist/core/publication.js +56 -0
- package/dist/core/published.d.ts +18 -0
- package/dist/core/published.js +83 -0
- package/dist/core/queries.d.ts +10 -0
- package/dist/core/queries.js +148 -0
- package/dist/core/query-batch.d.ts +2 -0
- package/dist/core/query-batch.js +67 -0
- package/dist/core/query-entries.d.ts +78 -0
- package/dist/core/query-entries.js +139 -0
- package/dist/core/query-response.d.ts +2 -0
- package/dist/core/query-response.js +110 -0
- package/dist/core/reads.d.ts +30 -0
- package/dist/core/reads.js +88 -0
- package/dist/core/rebase.d.ts +16 -0
- package/dist/core/rebase.js +40 -0
- package/dist/core/relations.d.ts +10 -0
- package/dist/core/relations.js +84 -0
- package/dist/core/remote-fields.d.ts +6 -0
- package/dist/core/remote-fields.js +29 -0
- package/dist/core/resolution.d.ts +12 -0
- package/dist/core/resolution.js +157 -0
- package/dist/core/restarts.d.ts +17 -0
- package/dist/core/restarts.js +42 -0
- package/dist/core/revisions.d.ts +11 -0
- package/dist/core/revisions.js +57 -0
- package/dist/core/row-arrays.d.ts +12 -0
- package/dist/core/row-arrays.js +47 -0
- package/dist/core/row-maps.d.ts +16 -0
- package/dist/core/row-maps.js +52 -0
- package/dist/core/row-states.d.ts +68 -0
- package/dist/core/row-states.js +75 -0
- package/dist/core/row-types.d.ts +76 -0
- package/dist/core/row-types.js +1 -0
- package/dist/core/rule-set-config.d.ts +56 -0
- package/dist/core/rule-set-config.js +1 -0
- package/dist/core/rule-set-types.d.ts +91 -0
- package/dist/core/rule-set-types.js +1 -0
- package/dist/core/rule-sets.d.ts +15 -0
- package/dist/core/rule-sets.js +107 -0
- package/dist/core/rules.d.ts +67 -0
- package/dist/core/rules.js +144 -0
- package/dist/core/saving.d.ts +55 -0
- package/dist/core/saving.js +132 -0
- package/dist/core/scope-declarations.d.ts +13 -0
- package/dist/core/scope-declarations.js +18 -0
- package/dist/core/scope-messages.d.ts +9 -0
- package/dist/core/scope-messages.js +46 -0
- package/dist/core/scope-states.d.ts +50 -0
- package/dist/core/scope-states.js +222 -0
- package/dist/core/session-external.d.ts +24 -0
- package/dist/core/session-external.js +138 -0
- package/dist/core/session-lists.d.ts +12 -0
- package/dist/core/session-lists.js +60 -0
- package/dist/core/session-marks.d.ts +22 -0
- package/dist/core/session-marks.js +113 -0
- package/dist/core/session-parts.d.ts +26 -0
- package/dist/core/session-parts.js +91 -0
- package/dist/core/session-rows.d.ts +15 -0
- package/dist/core/session-rows.js +62 -0
- package/dist/core/session-types.d.ts +112 -0
- package/dist/core/session-types.js +1 -0
- package/dist/core/session.d.ts +5 -0
- package/dist/core/session.js +51 -0
- package/dist/core/state-evaluation.d.ts +10 -0
- package/dist/core/state-evaluation.js +69 -0
- package/dist/core/state-properties.d.ts +30 -0
- package/dist/core/state-properties.js +101 -0
- package/dist/core/states.d.ts +73 -0
- package/dist/core/states.js +180 -0
- package/dist/core/steps.d.ts +37 -0
- package/dist/core/steps.js +183 -0
- package/dist/core/subtype-types.d.ts +67 -0
- package/dist/core/subtype-types.js +1 -0
- package/dist/core/subtypes.d.ts +19 -0
- package/dist/core/subtypes.js +69 -0
- package/dist/core/tree.d.ts +44 -0
- package/dist/core/tree.js +119 -0
- package/dist/core/validation.d.ts +11 -0
- package/dist/core/validation.js +42 -0
- package/dist/core/views.d.ts +24 -0
- package/dist/core/views.js +161 -0
- package/dist/react/async.d.ts +7 -0
- package/dist/react/async.js +67 -0
- package/dist/react/binding.d.ts +15 -0
- package/dist/react/binding.js +51 -0
- package/dist/react/coverage.d.ts +21 -0
- package/dist/react/coverage.js +91 -0
- package/dist/react/field.d.ts +60 -0
- package/dist/react/field.js +194 -0
- package/dist/react/form-state.d.ts +14 -0
- package/dist/react/form-state.js +70 -0
- package/dist/react/index.d.ts +152 -0
- package/dist/react/index.js +6 -0
- package/dist/react/opening.d.ts +38 -0
- package/dist/react/opening.js +206 -0
- package/dist/react/outputs.d.ts +11 -0
- package/dist/react/outputs.js +137 -0
- package/dist/react/props.d.ts +48 -0
- package/dist/react/props.js +1 -0
- package/dist/react/query.d.ts +11 -0
- package/dist/react/query.js +21 -0
- package/dist/react/render.d.ts +49 -0
- package/dist/react/render.js +119 -0
- package/dist/react/rows.d.ts +2 -0
- package/dist/react/rows.js +25 -0
- package/dist/react/visible-messages.d.ts +8 -0
- package/dist/react/visible-messages.js +16 -0
- package/package.json +77 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type OutputTools } from "./outputs.js";
|
|
2
|
+
import type { DefineForm } from "./config.js";
|
|
3
|
+
import type { Fields, FormDefinition } from "./definition.js";
|
|
4
|
+
import { type EndpointTable } from "./compiled.js";
|
|
5
|
+
import { type Messages } from "./messages.js";
|
|
6
|
+
type Config = {
|
|
7
|
+
readonly fields: Fields;
|
|
8
|
+
readonly collections?: unknown;
|
|
9
|
+
readonly context?: unknown;
|
|
10
|
+
readonly defaults?: unknown;
|
|
11
|
+
readonly include?: unknown;
|
|
12
|
+
readonly rules?: unknown;
|
|
13
|
+
readonly form?: unknown;
|
|
14
|
+
readonly outputs?: ((tools: OutputTools<Fields, unknown, unknown>) => unknown) | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare const defineFormFor: (table?: EndpointTable, messages?: Messages) => (config: Config) => FormDefinition;
|
|
17
|
+
export declare const defineForm: DefineForm<undefined>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// defineForm: it checks a configuration, copies and freezes its fields and
|
|
2
|
+
// collections, and compiles its rules. Only the definitions it returns open
|
|
3
|
+
// sessions.
|
|
4
|
+
import { defaultsOf, hasOnlyKeys } from "./fields.js";
|
|
5
|
+
import { compileOutputs } from "./outputs.js";
|
|
6
|
+
import { compileProperties } from "./rules.js";
|
|
7
|
+
import { sourcesOf } from "./rule-sets.js";
|
|
8
|
+
import { checkDeclared, compileCollections, positionsOf, shapeOf } from "./collections.js";
|
|
9
|
+
import { declaredStates } from "./states.js";
|
|
10
|
+
import { register } from "./compiled.js";
|
|
11
|
+
import { defaultMessages } from "./messages.js";
|
|
12
|
+
const sections = [
|
|
13
|
+
"fields",
|
|
14
|
+
"collections",
|
|
15
|
+
"context",
|
|
16
|
+
"defaults",
|
|
17
|
+
"include",
|
|
18
|
+
"rules",
|
|
19
|
+
"form",
|
|
20
|
+
"outputs",
|
|
21
|
+
];
|
|
22
|
+
export const defineFormFor = (table, messages = defaultMessages) => (config) => {
|
|
23
|
+
if (!hasOnlyKeys(config, sections))
|
|
24
|
+
throw new Error("Form configuration requires fields and optional collections/context/defaults/include/rules/form/outputs");
|
|
25
|
+
const { fields, endpoints, collections } = checkDeclared("Form", config.fields, config.collections, config.context, table);
|
|
26
|
+
checkDefaults(config);
|
|
27
|
+
const definition = Object.freeze({
|
|
28
|
+
fields: Object.freeze(fields),
|
|
29
|
+
collections: collections.definition,
|
|
30
|
+
});
|
|
31
|
+
const compiled = compileCollections(collections.checked);
|
|
32
|
+
register(definition, { ...compile(config, fields, compiled, endpoints, table), messages });
|
|
33
|
+
return definition;
|
|
34
|
+
};
|
|
35
|
+
const checkDefaults = ({ context: declared, defaults }) => {
|
|
36
|
+
if (defaults !== undefined && typeof defaults !== "function")
|
|
37
|
+
throw new Error("Form defaults must be a function of the context");
|
|
38
|
+
if (defaults !== undefined && declared === undefined)
|
|
39
|
+
throw new Error("Form defaults requires a context");
|
|
40
|
+
};
|
|
41
|
+
const compile = (config, fields, collections, endpoints, table) => {
|
|
42
|
+
const context = config.context !== undefined;
|
|
43
|
+
const receiver = { fields, collections, context, table };
|
|
44
|
+
const sources = sourcesOf(config.include, config.rules, receiver);
|
|
45
|
+
return {
|
|
46
|
+
fields: Object.freeze(fields),
|
|
47
|
+
...compileProperties(fields, collections, sources, config.form),
|
|
48
|
+
collections,
|
|
49
|
+
shape: shapeOf([...Object.keys(fields), ...collections.keys()]),
|
|
50
|
+
positions: positionsOf(Object.keys(fields)),
|
|
51
|
+
declared: declaredStates(fields),
|
|
52
|
+
outputs: compileOutputs(config.outputs),
|
|
53
|
+
endpoints,
|
|
54
|
+
context,
|
|
55
|
+
defaults: config.defaults,
|
|
56
|
+
fieldDefaults: defaultsOf(fields),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
// The checks of its signature are types only.
|
|
60
|
+
export const defineForm = defineFormFor();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Messages } from "./messages.js";
|
|
2
|
+
import type { FieldDefinition } from "./fields.js";
|
|
3
|
+
import type { ResolvedEndpoint } from "./endpoints.js";
|
|
4
|
+
import type { CompiledOutputs } from "./outputs.js";
|
|
5
|
+
import type { CompiledQuery } from "./params.js";
|
|
6
|
+
import type { EachObserver, FieldEvent, FieldFormula, Observer, StateFormula } from "./rules.js";
|
|
7
|
+
import type { CompiledCollection } from "./collections.js";
|
|
8
|
+
import type { States } from "./states.js";
|
|
9
|
+
import type { FormDefinition } from "./definition.js";
|
|
10
|
+
export type EndpointTable = ReadonlyMap<string, ResolvedEndpoint>;
|
|
11
|
+
export type Compiled = {
|
|
12
|
+
readonly fields: Readonly<Record<string, FieldDefinition>>;
|
|
13
|
+
readonly formulas: ReadonlyMap<string, FieldFormula>;
|
|
14
|
+
readonly events: ReadonlyMap<string, FieldEvent>;
|
|
15
|
+
readonly hasEdits: boolean;
|
|
16
|
+
readonly hasRelations: boolean;
|
|
17
|
+
readonly observers: readonly (Observer | EachObserver)[];
|
|
18
|
+
readonly states: readonly StateFormula[];
|
|
19
|
+
readonly locks: readonly StateFormula[];
|
|
20
|
+
readonly own: readonly StateFormula[];
|
|
21
|
+
readonly collections: ReadonlyMap<string, CompiledCollection>;
|
|
22
|
+
readonly shape: object;
|
|
23
|
+
readonly positions: ReadonlyMap<string, number>;
|
|
24
|
+
readonly declared: States;
|
|
25
|
+
readonly outputs: CompiledOutputs;
|
|
26
|
+
readonly endpoints: EndpointTable;
|
|
27
|
+
readonly queries: ReadonlyMap<string, CompiledQuery>;
|
|
28
|
+
readonly context: boolean;
|
|
29
|
+
readonly defaults: ((context: object) => unknown) | undefined;
|
|
30
|
+
readonly messages: Messages;
|
|
31
|
+
readonly fieldDefaults: Readonly<Record<string, unknown>>;
|
|
32
|
+
};
|
|
33
|
+
export declare const register: (definition: FormDefinition, form: Compiled) => void;
|
|
34
|
+
export declare const compiledFor: (definition: FormDefinition) => Compiled;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Identity is the only link between a definition and its compiled form, so
|
|
2
|
+
// copies and hand-written objects are rejected instead of opening without rules.
|
|
3
|
+
const compiled = new WeakMap();
|
|
4
|
+
export const register = (definition, form) => {
|
|
5
|
+
compiled.set(definition, form);
|
|
6
|
+
};
|
|
7
|
+
export const compiledFor = (definition) => {
|
|
8
|
+
const found = compiled.get(definition);
|
|
9
|
+
if (found === undefined)
|
|
10
|
+
throw new Error("Form definition must be created with defineForm");
|
|
11
|
+
return found;
|
|
12
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { CoreDefinition, RemoteDefinition } from "./fields.js";
|
|
2
|
+
import type { RemoteFieldOf } from "./endpoints.js";
|
|
3
|
+
import type { OutputTools, OutputReferences } from "./outputs.js";
|
|
4
|
+
import type { DefaultsRules, PropertyRules, RequiredCollections, RequiredEntries } from "./authoring.js";
|
|
5
|
+
import type { Keys, Verdict } from "./authoring-checks.js";
|
|
6
|
+
import type { FormRules } from "./authoring-form.js";
|
|
7
|
+
import type { QueryState } from "./queries.js";
|
|
8
|
+
import type { IncludeChecks, Includable, IncludedQueries, IncludedRowQueries } from "./rule-set-types.js";
|
|
9
|
+
import type { ParamsLeftRules } from "./authoring-params.js";
|
|
10
|
+
import type { Collections, ContextDeclaration, Fields, FieldsIn, FormDefinition } from "./definition.js";
|
|
11
|
+
export type PropertyIn<P, X, Key extends string> = P extends unknown ? X extends keyof P ? PropertyOf<P[X], Key> : undefined : never;
|
|
12
|
+
type PropertyOf<E, Key extends string> = E extends object ? Key extends keyof E ? E[Key] : undefined : undefined;
|
|
13
|
+
type QueryIn<P, K> = PropertyIn<P, K, "query">;
|
|
14
|
+
type QueryNames<P> = {
|
|
15
|
+
[K in Keys<P>]: [NonNullable<QueryIn<P, K>>] extends [never] ? never : K;
|
|
16
|
+
}[Keys<P>];
|
|
17
|
+
type SureNames<P> = {
|
|
18
|
+
[K in QueryNames<P>]: undefined extends QueryIn<P, K> ? never : K;
|
|
19
|
+
}[QueryNames<P>];
|
|
20
|
+
export type StatesOf<All, Sure> = {
|
|
21
|
+
readonly [K in Sure & PropertyKey]: QueryState;
|
|
22
|
+
} & {
|
|
23
|
+
readonly [K in Exclude<All, Sure> & PropertyKey]?: QueryState;
|
|
24
|
+
};
|
|
25
|
+
export type QueriesOf<P> = [QueryNames<P>] extends [never] ? {} : StatesOf<QueryNames<P>, SureNames<P>> extends infer T ? {
|
|
26
|
+
[K in keyof T]: T[K];
|
|
27
|
+
} : never;
|
|
28
|
+
export type EachIn<P, N> = PropertyIn<P, N, "each">;
|
|
29
|
+
export type RowQueriesOf<P, K> = [keyof K] extends [never] ? {} : {
|
|
30
|
+
readonly [N in keyof K]: QueriesOf<EachIn<P, N>>;
|
|
31
|
+
};
|
|
32
|
+
type AnyQuery<P, K> = QueryNames<P> | {
|
|
33
|
+
[N in keyof K]-?: QueryNames<EachIn<P, N>>;
|
|
34
|
+
}[keyof K];
|
|
35
|
+
type NoOutputs<O> = {} extends O ? undefined : never;
|
|
36
|
+
export type NoContext<C> = undefined extends C ? undefined : never;
|
|
37
|
+
type NoQueries<P, K> = [AnyQuery<P, K>] extends [never] ? undefined : never;
|
|
38
|
+
export type Declared<K> = [K] extends [Collections] ? K : {};
|
|
39
|
+
type CollectionsPresent<K> = [keyof K] extends [never] ? unknown : {
|
|
40
|
+
readonly collections: K;
|
|
41
|
+
};
|
|
42
|
+
type Needs<N, T> = [N] extends [never] ? unknown : {
|
|
43
|
+
readonly rules: T;
|
|
44
|
+
};
|
|
45
|
+
type RulesRequired<F extends Fields, K, P, I> = ([I] extends [undefined] ? Needs<RequiredEntries<F> | RequiredCollections<K>, object> : ParamsLeftRules<F, K, I>) & Needs<AnyQuery<P, K>, unknown>;
|
|
46
|
+
type FormConfig<F extends Fields, O extends Record<string, unknown>, P, L, C, X, M, K, I> = {
|
|
47
|
+
readonly fields: F;
|
|
48
|
+
readonly collections?: K | undefined;
|
|
49
|
+
readonly context?: ContextDeclaration<C> | NoContext<C>;
|
|
50
|
+
readonly defaults?: DefaultsRules<NoInfer<F>, NoInfer<C>, X> | undefined;
|
|
51
|
+
readonly rules?: PropertyRules<NoInfer<F>, NoInfer<Declared<K>>, NoInfer<C>, P, M, I> | NoQueries<P, NoInfer<Declared<K>>>;
|
|
52
|
+
readonly form?: FormRules<NoInfer<F>, NoInfer<Declared<K>>, NoInfer<C>, L> | undefined;
|
|
53
|
+
readonly outputs?: (<Owner>(tools: OutputTools<NoInfer<F>, NoInfer<C>, Owner, NoInfer<Declared<K>>>) => OutputReferences<O, Owner>) | NoOutputs<O>;
|
|
54
|
+
} & {
|
|
55
|
+
readonly rules?: P | undefined;
|
|
56
|
+
readonly form?: L | undefined;
|
|
57
|
+
readonly defaults?: X | undefined;
|
|
58
|
+
} & RulesRequired<NoInfer<F>, NoInfer<Declared<K>>, NoInfer<P>, I> & CollectionsPresent<NoInfer<Declared<K>>>;
|
|
59
|
+
type Rejection<Label extends string, D, Bound, Owner> = D extends {
|
|
60
|
+
readonly subtype: infer N extends string;
|
|
61
|
+
} ? Bound extends true ? `${Label} (subtype "${N}") belongs to other forms` : `${Label} (subtype "${N}"): ${Unbound<Owner>}` : D extends RemoteDefinition ? Bound extends true ? `${Label} (${D["type"]}): unknown endpoint "${D["endpoint"]}"` : `${Label} (${D["type"]}): ${Unbound<Owner>}` : never;
|
|
62
|
+
type Unbound<Owner> = Owner extends "Form" ? "define the form with the defineForm of createForms" : "define the rule set with the defineRules of createForms";
|
|
63
|
+
type Tagged = {
|
|
64
|
+
readonly subtype: string;
|
|
65
|
+
};
|
|
66
|
+
type Foreign<D, Allowed> = [D] extends [{
|
|
67
|
+
readonly type: string;
|
|
68
|
+
readonly subtype?: undefined;
|
|
69
|
+
}] ? never : Exclude<Extract<D, Tagged>, Extract<Allowed, Tagged>>;
|
|
70
|
+
type Rejected<D, Allowed> = Exclude<D, Allowed> | Foreign<D, Allowed>;
|
|
71
|
+
type FieldsOf<F> = F extends unknown ? F[keyof F] : never;
|
|
72
|
+
export type Admitted<F extends Fields, Allowed, Bound, Owner = "Form"> = [
|
|
73
|
+
Rejected<FieldsOf<F>, Allowed>
|
|
74
|
+
] extends [never] ? unknown : {
|
|
75
|
+
readonly [K in keyof F]: [Rejected<F[K], Allowed>] extends [never] ? unknown : Rejection<`Field "${K & string}"`, F[K], Bound, Owner>;
|
|
76
|
+
};
|
|
77
|
+
type CollectionMessage<F extends Fields, N, R extends Fields, Allowed, Bound, Owner> = N extends keyof F ? `collection "${N & string}" has the name of a field` : [Rejected<FieldsOf<R>, Allowed>] extends [never] ? never : {
|
|
78
|
+
readonly fields: {
|
|
79
|
+
readonly [X in keyof R]: [Rejected<R[X], Allowed>] extends [never] ? unknown : Rejection<`Field "${X & string}" of "${N & string}"`, R[X], Bound, Owner>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export type AdmittedCollections<F extends Fields, K, Allowed, Bound, Owner = "Form"> = [
|
|
83
|
+
{
|
|
84
|
+
[N in keyof K]: CollectionMessage<F, N, FieldsIn<K[N]>, Allowed, Bound, Owner>;
|
|
85
|
+
}[keyof K]
|
|
86
|
+
] extends [never] ? unknown : {
|
|
87
|
+
readonly [N in keyof K]: Verdict<CollectionMessage<F, N, FieldsIn<K[N]>, Allowed, Bound, Owner>>;
|
|
88
|
+
};
|
|
89
|
+
export type DefineForm<M, Allowed = CoreDefinition | RemoteFieldOf<M>, Bound extends boolean = [M] extends [undefined] ? false : true> = <const F extends Fields, const O extends Record<string, unknown> = {}, P = {}, L = {}, C = undefined, X = unknown, const K extends Collections | undefined = {}, const I extends readonly Includable[] | undefined = undefined>(config: FormConfig<F, O, P, L, C, X, M, K, I> & {
|
|
90
|
+
readonly fields: NoInfer<Admitted<F, Allowed, Bound>>;
|
|
91
|
+
readonly collections?: NoInfer<AdmittedCollections<F, Declared<K>, Allowed, Bound>> | undefined;
|
|
92
|
+
readonly include?: Include<F, Declared<K>, C, M, I, P>;
|
|
93
|
+
}) => FormDefinition<F, O, C, [
|
|
94
|
+
I
|
|
95
|
+
] extends [undefined] ? QueriesOf<P> : Joined<QueriesOf<P>, IncludedQueries<I>>, Declared<K>, JoinedRows<RowQueriesOf<P, Declared<K>>, I, Declared<K>>>;
|
|
96
|
+
type Include<F, K, C, M, I, P> = [I] extends [undefined] ? readonly Includable[] | undefined : NoInfer<IncludeChecks<F, K, C, M, I, P>> & I;
|
|
97
|
+
type Joined<A, B> = [keyof B] extends [never] ? A : {
|
|
98
|
+
[X in keyof (A & B)]: (A & B)[X];
|
|
99
|
+
} extends infer T extends Record<string, QueryState> ? T : never;
|
|
100
|
+
type JoinedRows<W, I, K> = [I] extends [undefined] ? W : {
|
|
101
|
+
readonly [N in keyof W]: Joined<W[N], IncludedRowQueries<I, N & keyof K>>;
|
|
102
|
+
} extends infer T extends Record<string, Readonly<Record<string, QueryState>>> ? T : never;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Field } from "./address.js";
|
|
2
|
+
import type { FieldEvent } from "./rules.js";
|
|
3
|
+
export type { Field } from "./address.js";
|
|
4
|
+
export type Step = Field | FieldEvent;
|
|
5
|
+
export declare const isEvent: (step: Step) => step is FieldEvent;
|
|
6
|
+
export type Deferred = {
|
|
7
|
+
readonly event: FieldEvent;
|
|
8
|
+
readonly name: Field;
|
|
9
|
+
readonly stack: readonly Step[];
|
|
10
|
+
readonly step: Step;
|
|
11
|
+
};
|
|
12
|
+
export declare const annotate: (annotations: Map<FieldEvent, Deferred[]>, deferred: Deferred) => void;
|
|
13
|
+
export declare const writerEdge: (stack: readonly Step[], step: Step, skip: readonly FieldEvent[]) => FieldEvent | undefined;
|
|
14
|
+
export declare const cycle: (stack: readonly Step[], step: Step) => Error;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { labelAt, pathLabel } from "./address.js";
|
|
2
|
+
export const isEvent = (step) => typeof step === "object" && "handler" in step;
|
|
3
|
+
// Keeps the annotations of each event in the order they happened, so that its
|
|
4
|
+
// patch checks only its own.
|
|
5
|
+
export const annotate = (annotations, deferred) => {
|
|
6
|
+
const list = annotations.get(deferred.event);
|
|
7
|
+
if (list === undefined)
|
|
8
|
+
annotations.set(deferred.event, [deferred]);
|
|
9
|
+
else
|
|
10
|
+
list.push(deferred);
|
|
11
|
+
};
|
|
12
|
+
// The first writer edge on the path of a cycle: a field that settles and, right
|
|
13
|
+
// above it, one of its writer events, skipping the events given. The path runs
|
|
14
|
+
// above the last appearance of the step reached again: the edge that leaves the
|
|
15
|
+
// step is the one being confirmed, or not a writer edge.
|
|
16
|
+
export const writerEdge = (stack, step, skip) => {
|
|
17
|
+
for (let at = stack.lastIndexOf(step) + 1; at < stack.length - 1; at++) {
|
|
18
|
+
const event = stack[at + 1];
|
|
19
|
+
if (event !== undefined &&
|
|
20
|
+
!isEvent(stack[at]) &&
|
|
21
|
+
isEvent(event) &&
|
|
22
|
+
!skip.includes(event))
|
|
23
|
+
return event;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
};
|
|
27
|
+
// The cycle closes at the step reached again. An event that closes it, as the
|
|
28
|
+
// writer skipped or as the reader, is named; otherwise the field reached again is.
|
|
29
|
+
// A field that completes without its writer event appears twice on the stack, so
|
|
30
|
+
// the path starts at its last appearance.
|
|
31
|
+
export const cycle = (stack, step) => {
|
|
32
|
+
const reader = stack.at(-1);
|
|
33
|
+
const closer = !isEvent(step) && reader !== undefined && isEvent(reader) ? reader : step;
|
|
34
|
+
const rule = isEvent(closer) ? closer.label : `${labelAt(closer)} value`;
|
|
35
|
+
const path = [...stack.slice(stack.lastIndexOf(step)), step].map((item) => isEvent(item)
|
|
36
|
+
? `${pathLabel(item.address)}.${item.edit ? "onEdit" : "onChange"}`
|
|
37
|
+
: pathLabel(item));
|
|
38
|
+
return new Error(`${rule}: cyclic dependency ${path.join(" → ")}`);
|
|
39
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type DeepReadonly<T> = {
|
|
2
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
3
|
+
};
|
|
4
|
+
export type PlainData = string | number | boolean | null | undefined | readonly PlainData[] | {
|
|
5
|
+
readonly [key: string]: PlainData;
|
|
6
|
+
};
|
|
7
|
+
export type PlainRecord = {
|
|
8
|
+
readonly [key: string]: PlainData;
|
|
9
|
+
};
|
|
10
|
+
export type OptionShape = {
|
|
11
|
+
readonly value: string | number;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
};
|
|
14
|
+
export type PlainOption = OptionShape & PlainRecord;
|
|
15
|
+
type Reserved = {
|
|
16
|
+
readonly value?: 'option metadata cannot declare "value"';
|
|
17
|
+
readonly label?: 'option metadata cannot declare "label"';
|
|
18
|
+
};
|
|
19
|
+
export type Option<Metadata extends PlainRecord & Reserved = {}, Value extends string | number = string | number> = DeepReadonly<{
|
|
20
|
+
value: Value;
|
|
21
|
+
label: string;
|
|
22
|
+
} & Metadata>;
|
|
23
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
24
|
+
export declare const isPlainRecord: (value: unknown) => value is Record<string, unknown>;
|
|
25
|
+
export declare const own: (value: object, key: PropertyKey) => unknown;
|
|
26
|
+
export declare const isKey: (value: unknown) => value is string | number;
|
|
27
|
+
export declare const isOption: (value: unknown) => value is OptionShape;
|
|
28
|
+
export declare const arrayIndex: (key: string) => number | undefined;
|
|
29
|
+
export declare const dataProblem: (value: unknown, subject: string) => string | undefined;
|
|
30
|
+
export declare const copyData: (value: unknown, subject: string) => unknown;
|
|
31
|
+
export declare const isCopy: (value: unknown) => boolean;
|
|
32
|
+
export declare const copiedArray: <T>(items: T[]) => readonly T[];
|
|
33
|
+
export declare const canonicalParams: (value: unknown, prefix: string) => unknown;
|
|
34
|
+
export declare const copyOutput: (value: unknown, ancestors?: Set<object>) => unknown;
|
|
35
|
+
export declare const equal: (left: unknown, right: unknown) => boolean;
|
|
36
|
+
export declare const sameItems: <T>(a: readonly T[], b: readonly T[], same?: (item: T, index: number) => boolean) => boolean;
|
|
37
|
+
export declare const defineOwn: (target: object, name: PropertyKey, value?: unknown) => object;
|
|
38
|
+
export declare const ownEntries: (value: object) => (readonly [string | symbol, any])[];
|
|
39
|
+
export declare const describe: (value: unknown) => string;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Plain data: frozen copies in depth, structural equality, and the canonical
|
|
2
|
+
// form of the params that go into the keys of the loader.
|
|
3
|
+
export const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
export const isPlainRecord = (value) => {
|
|
5
|
+
if (!isRecord(value))
|
|
6
|
+
return false;
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
return prototype === Object.prototype || prototype === null;
|
|
9
|
+
};
|
|
10
|
+
// The value of an own data property, read without running code; undefined
|
|
11
|
+
// for an accessor or a missing property.
|
|
12
|
+
export const own = (value, key) => {
|
|
13
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
14
|
+
return descriptor !== undefined && "value" in descriptor ? descriptor.value : undefined;
|
|
15
|
+
};
|
|
16
|
+
// A string or a finite number: what identifies an option or a scope.
|
|
17
|
+
export const isKey = (value) => typeof value === "string" || Number.isFinite(value);
|
|
18
|
+
// Whether a value has the shape of an option: a plain object with its own
|
|
19
|
+
// value and its own label.
|
|
20
|
+
export const isOption = (value) => isPlainRecord(value) && isKey(own(value, "value")) && typeof own(value, "label") === "string";
|
|
21
|
+
// A name that JavaScript orders as an array index, as a number.
|
|
22
|
+
export const arrayIndex = (key) => /^(?:0|[1-9]\d*)$/u.test(key) && Number(key) < 2 ** 32 - 1 ? Number(key) : undefined;
|
|
23
|
+
// What Trama already copied and froze as plain data. An output keeps it as it
|
|
24
|
+
// is; any other result is copied.
|
|
25
|
+
const copies = new WeakSet();
|
|
26
|
+
const issues = new WeakSet();
|
|
27
|
+
const issue = (text, path, plain = false) => {
|
|
28
|
+
const found = Object.assign(new Error(text), { path, plain });
|
|
29
|
+
issues.add(found);
|
|
30
|
+
return found;
|
|
31
|
+
};
|
|
32
|
+
const describeIssue = ({ message, path, plain }, subject) => {
|
|
33
|
+
const at = path === "" ? "" : ` at "${path}"`;
|
|
34
|
+
return plain ? `${subject} ${message}${at}` : `${message}${at}`;
|
|
35
|
+
};
|
|
36
|
+
const notPlain = (what, path) => issue(`must be plain data: ${what}`, path, true);
|
|
37
|
+
const article = (name) => (/^[aeiou]/iu.test(name) ? `an ${name}` : `a ${name}`);
|
|
38
|
+
const child = (path, key) => typeof key === "number" ? `${path}[${key}]` : path === "" ? key : `${path}.${key}`;
|
|
39
|
+
const primitive = (value, path) => {
|
|
40
|
+
if (typeof value === "number")
|
|
41
|
+
return Number.isFinite(value) ? undefined : notPlain("a non-finite number", path);
|
|
42
|
+
if (typeof value === "function")
|
|
43
|
+
return notPlain("a function", path);
|
|
44
|
+
if (typeof value === "bigint" || typeof value === "symbol")
|
|
45
|
+
return notPlain(`a ${typeof value}`, path);
|
|
46
|
+
};
|
|
47
|
+
// The kind of an object that is not plain, read without running its code.
|
|
48
|
+
const kindOf = (value) => {
|
|
49
|
+
const prototype = Object.getPrototypeOf(value);
|
|
50
|
+
const plain = Array.isArray(value)
|
|
51
|
+
? prototype === Array.prototype
|
|
52
|
+
: prototype === null || prototype === Object.prototype;
|
|
53
|
+
if (plain)
|
|
54
|
+
return;
|
|
55
|
+
const constructor = typeof prototype === "object" && prototype !== null ? own(prototype, "constructor") : undefined;
|
|
56
|
+
const name = typeof constructor === "function" ? constructor.name : undefined;
|
|
57
|
+
return typeof name === "string" && name !== "" ? article(name) : "an object with a prototype";
|
|
58
|
+
};
|
|
59
|
+
const walk = (value, path, mode, ancestors, memo) => {
|
|
60
|
+
if (typeof value !== "object" || value === null) {
|
|
61
|
+
const found = primitive(value, path);
|
|
62
|
+
if (found !== undefined)
|
|
63
|
+
throw found;
|
|
64
|
+
return mode === "canonical" && Object.is(value, -0) ? 0 : value;
|
|
65
|
+
}
|
|
66
|
+
if (copies.has(value) && mode !== "canonical")
|
|
67
|
+
return value;
|
|
68
|
+
const kind = kindOf(value);
|
|
69
|
+
if (kind !== undefined)
|
|
70
|
+
throw notPlain(kind, path);
|
|
71
|
+
if (ancestors.has(value))
|
|
72
|
+
throw notPlain("a cycle", path);
|
|
73
|
+
const done = memo.get(value);
|
|
74
|
+
if (done !== undefined)
|
|
75
|
+
return done;
|
|
76
|
+
ancestors.add(value);
|
|
77
|
+
const array = Array.isArray(value);
|
|
78
|
+
const copy = mode === "check"
|
|
79
|
+
? undefined
|
|
80
|
+
: array
|
|
81
|
+
? []
|
|
82
|
+
: Object.create(Object.getPrototypeOf(value));
|
|
83
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
84
|
+
if (array && key === "length")
|
|
85
|
+
continue;
|
|
86
|
+
const entry = entryOf(value, key, path, array, mode);
|
|
87
|
+
if (entry === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
const item = walk(entry.value, entry.at, mode, ancestors, memo);
|
|
90
|
+
if (copy !== undefined)
|
|
91
|
+
Object.defineProperty(copy, key, { value: item, enumerable: true, writable: true });
|
|
92
|
+
}
|
|
93
|
+
// A hole in an array reads as undefined.
|
|
94
|
+
if (array && mode === "canonical" && Reflect.ownKeys(value).length - 1 < value.length)
|
|
95
|
+
throw issue("undefined is not allowed inside arrays", child(path, firstHole(value)));
|
|
96
|
+
ancestors.delete(value);
|
|
97
|
+
if (copy === undefined)
|
|
98
|
+
return value;
|
|
99
|
+
if (array)
|
|
100
|
+
Reflect.set(copy, "length", value.length);
|
|
101
|
+
Object.freeze(copy);
|
|
102
|
+
copies.add(copy);
|
|
103
|
+
memo.set(value, copy);
|
|
104
|
+
return copy;
|
|
105
|
+
};
|
|
106
|
+
// The value of a data property and where it is, or undefined when the
|
|
107
|
+
// canonical form drops it. Nothing it reads runs code.
|
|
108
|
+
const entryOf = (value, key, path, array, mode) => {
|
|
109
|
+
if (typeof key === "symbol")
|
|
110
|
+
throw notPlain("a symbol key", path);
|
|
111
|
+
const index = array ? arrayIndex(key) : undefined;
|
|
112
|
+
const at = child(path, index ?? key);
|
|
113
|
+
if (array && index === undefined)
|
|
114
|
+
throw notPlain("an array property", at);
|
|
115
|
+
// JSON keys of Query lose an own __proto__, and read constructor to tell plain objects apart.
|
|
116
|
+
if (mode === "canonical" && (key === "__proto__" || key === "constructor"))
|
|
117
|
+
throw issue(`"${key}" is not allowed as a key`, path);
|
|
118
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
119
|
+
if (!("value" in descriptor))
|
|
120
|
+
throw notPlain(descriptor.get === undefined ? "a setter" : "a getter", at);
|
|
121
|
+
if (descriptor.enumerable !== true)
|
|
122
|
+
throw notPlain("a non-enumerable property", at);
|
|
123
|
+
if (descriptor.value !== undefined || mode !== "canonical")
|
|
124
|
+
return { value: descriptor.value, at };
|
|
125
|
+
if (array)
|
|
126
|
+
throw issue("undefined is not allowed inside arrays", at);
|
|
127
|
+
};
|
|
128
|
+
const firstHole = (array) => {
|
|
129
|
+
for (let index = 0; index < array.length; index += 1)
|
|
130
|
+
if (!(index in array))
|
|
131
|
+
return index;
|
|
132
|
+
return array.length;
|
|
133
|
+
};
|
|
134
|
+
// Walks a value, or returns why it is not plain data.
|
|
135
|
+
const inspect = (value, mode) => {
|
|
136
|
+
try {
|
|
137
|
+
return { value: walk(value, "", mode, new Set(), new Map()) };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error instanceof Error && issues.has(error))
|
|
141
|
+
return { issue: error };
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
// Why a value is not plain data, as "<subject> must be plain data: a Date at
|
|
146
|
+
// "since"", or undefined when it is.
|
|
147
|
+
export const dataProblem = (value, subject) => {
|
|
148
|
+
const found = inspect(value, "check").issue;
|
|
149
|
+
return found === undefined ? undefined : describeIssue(found, subject);
|
|
150
|
+
};
|
|
151
|
+
// A frozen copy in depth of plain data. Data Trama already copied is kept as
|
|
152
|
+
// it is.
|
|
153
|
+
export const copyData = (value, subject) => {
|
|
154
|
+
const inspected = inspect(value, "copy");
|
|
155
|
+
if (inspected.issue !== undefined)
|
|
156
|
+
throw new Error(describeIssue(inspected.issue, subject));
|
|
157
|
+
return inspected.value;
|
|
158
|
+
};
|
|
159
|
+
// Whether Trama copied and froze a value as plain data.
|
|
160
|
+
export const isCopy = (value) => typeof value === "object" && value !== null && copies.has(value);
|
|
161
|
+
// A frozen array of items that are primitives or copies already, kept as a
|
|
162
|
+
// copy without walking it again. The items must be plain data.
|
|
163
|
+
export const copiedArray = (items) => {
|
|
164
|
+
Object.freeze(items);
|
|
165
|
+
copies.add(items);
|
|
166
|
+
return items;
|
|
167
|
+
};
|
|
168
|
+
// The canonical copy of params, whose diagnostics start with prefix: equal
|
|
169
|
+
// params for Trama are equal in JSON, so a cache that hashes keys as JSON, as
|
|
170
|
+
// Query does, tells them apart.
|
|
171
|
+
export const canonicalParams = (value, prefix) => {
|
|
172
|
+
const inspected = inspect(value, "canonical");
|
|
173
|
+
if (inspected.issue === undefined)
|
|
174
|
+
return inspected.value;
|
|
175
|
+
throw new Error(`${prefix}: ${describeIssue(inspected.issue, "result")}`);
|
|
176
|
+
};
|
|
177
|
+
// The frozen copy in depth of an output result. It admits more than plain
|
|
178
|
+
// data, as the outputs always did, and keeps its own diagnostics.
|
|
179
|
+
export const copyOutput = (value, ancestors = new Set()) => {
|
|
180
|
+
if (typeof value === "function")
|
|
181
|
+
throw new Error("Output results cannot contain functions");
|
|
182
|
+
if (typeof value !== "object" || value === null || copies.has(value))
|
|
183
|
+
return value;
|
|
184
|
+
const prototype = Object.getPrototypeOf(value);
|
|
185
|
+
if (prototype !== (Array.isArray(value) ? Array.prototype : Object.prototype) &&
|
|
186
|
+
prototype !== null)
|
|
187
|
+
throw new Error("Output results require arrays or plain data objects");
|
|
188
|
+
if (ancestors.has(value))
|
|
189
|
+
throw new Error("Output results cannot contain cycles");
|
|
190
|
+
ancestors.add(value);
|
|
191
|
+
const copy = Array.isArray(value) ? [] : Object.create(prototype);
|
|
192
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
193
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
194
|
+
if (!descriptor || !("value" in descriptor))
|
|
195
|
+
throw new Error("Output results require data properties");
|
|
196
|
+
Object.defineProperty(copy, key, {
|
|
197
|
+
value: copyOutput(descriptor.value, ancestors),
|
|
198
|
+
enumerable: descriptor.enumerable ?? false,
|
|
199
|
+
configurable: !(key === "length" && Array.isArray(value)),
|
|
200
|
+
writable: true,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
ancestors.delete(value);
|
|
204
|
+
return Object.freeze(copy);
|
|
205
|
+
};
|
|
206
|
+
// Structural equality of data, which tells -0 from 0.
|
|
207
|
+
export const equal = (left, right) => {
|
|
208
|
+
if (Object.is(left, right))
|
|
209
|
+
return true;
|
|
210
|
+
if (typeof left !== "object" || left === null || typeof right !== "object" || right === null)
|
|
211
|
+
return false;
|
|
212
|
+
if (Object.getPrototypeOf(left) !== Object.getPrototypeOf(right))
|
|
213
|
+
return false;
|
|
214
|
+
const keys = Reflect.ownKeys(left);
|
|
215
|
+
return (keys.length === Reflect.ownKeys(right).length &&
|
|
216
|
+
keys.every((key) => Object.hasOwn(right, key) && equal(Reflect.get(left, key), Reflect.get(right, key))));
|
|
217
|
+
};
|
|
218
|
+
// Whether two arrays hold the same items: the same objects, or as equal says.
|
|
219
|
+
export const sameItems = (a, b, same = (item, index) => item === b[index]) => a === b || (a.length === b.length && a.every((item, index) => same(item, index)));
|
|
220
|
+
// Defines an own data property. Assigning __proto__ would set the prototype
|
|
221
|
+
// instead of the property.
|
|
222
|
+
export const defineOwn = (target, name, value) => Object.defineProperty(target, name, {
|
|
223
|
+
value,
|
|
224
|
+
enumerable: true,
|
|
225
|
+
writable: true,
|
|
226
|
+
configurable: true,
|
|
227
|
+
});
|
|
228
|
+
// The own entries of an object, symbols included, read as a rule reads them:
|
|
229
|
+
// a getter runs.
|
|
230
|
+
export const ownEntries = (value) => Reflect.ownKeys(value).map((key) => [key, Reflect.get(value, key)]);
|
|
231
|
+
// A value as diagnostics name it.
|
|
232
|
+
export const describe = (value) => typeof value === "string"
|
|
233
|
+
? JSON.stringify(value)
|
|
234
|
+
: (typeof value === "object" && value !== null) || typeof value === "function"
|
|
235
|
+
? Object.prototype.toString.call(value)
|
|
236
|
+
: String(value);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Fields } from "./definition.js";
|
|
2
|
+
import { type CheckedQuery } from "./params.js";
|
|
3
|
+
import type { RuleFormula } from "./reads.js";
|
|
4
|
+
import type { EndpointTable } from "./compiled.js";
|
|
5
|
+
import type { Owner } from "./remote-fields.js";
|
|
6
|
+
import type { Own } from "./rules.js";
|
|
7
|
+
export declare const policies: {
|
|
8
|
+
readonly disabled: "accumulate";
|
|
9
|
+
readonly readOnly: "accumulate";
|
|
10
|
+
readonly hidden: "accumulate";
|
|
11
|
+
readonly required: "accumulate";
|
|
12
|
+
readonly label: "accumulate";
|
|
13
|
+
readonly placeholder: "accumulate";
|
|
14
|
+
readonly decimals: "accumulate";
|
|
15
|
+
readonly min: "accumulate";
|
|
16
|
+
readonly max: "accumulate";
|
|
17
|
+
readonly error: "accumulate";
|
|
18
|
+
readonly warning: "accumulate";
|
|
19
|
+
readonly value: "single";
|
|
20
|
+
readonly relation: "single";
|
|
21
|
+
readonly onChange: "single";
|
|
22
|
+
readonly onEdit: "single";
|
|
23
|
+
readonly params: "single";
|
|
24
|
+
readonly query: "single";
|
|
25
|
+
readonly states: "accumulate";
|
|
26
|
+
};
|
|
27
|
+
export type Property = keyof typeof policies;
|
|
28
|
+
export declare const eventConflict: (label: string, first: string, second: string) => Error;
|
|
29
|
+
export type Declaration = {
|
|
30
|
+
readonly collection: string | undefined;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly label: string;
|
|
33
|
+
readonly own?: Own | undefined;
|
|
34
|
+
readonly drivenBy?: string | undefined;
|
|
35
|
+
} & ({
|
|
36
|
+
readonly property: "query";
|
|
37
|
+
readonly query: CheckedQuery;
|
|
38
|
+
} | {
|
|
39
|
+
readonly property: "relation";
|
|
40
|
+
readonly members: readonly string[];
|
|
41
|
+
} | {
|
|
42
|
+
readonly property: Exclude<Property, "query" | "relation">;
|
|
43
|
+
readonly formulas: readonly (readonly [suffix: string, formula: RuleFormula])[];
|
|
44
|
+
});
|
|
45
|
+
type Collection = {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
readonly fields: Fields;
|
|
48
|
+
};
|
|
49
|
+
export declare const declarationsOf: (owner: Owner, fields: Fields, collections: ReadonlyMap<string, Collection>, rules: unknown, table: EndpointTable | undefined) => readonly Declaration[];
|
|
50
|
+
export declare const messagesOf: (label: string, rules: string, own: Own, declared: unknown) => Extract<Declaration, {
|
|
51
|
+
readonly formulas: unknown;
|
|
52
|
+
}>[];
|
|
53
|
+
type Claim = {
|
|
54
|
+
readonly property: Declaration["property"];
|
|
55
|
+
readonly drivenBy: string | undefined;
|
|
56
|
+
readonly place: string;
|
|
57
|
+
};
|
|
58
|
+
export type Claims = Map<string, Claim>;
|
|
59
|
+
export declare const claim: (claimed: Claims, { name, label, property, drivenBy }: Declaration, place: string) => void;
|
|
60
|
+
export declare const checkSetClaims: (declarations: readonly Declaration[]) => void;
|
|
61
|
+
export {};
|