@spotto/semantic-query 1.0.70-alpha.34 → 1.0.70-alpha.36

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/dist/types.d.ts CHANGED
@@ -1,111 +1,111 @@
1
- import { FieldDataType, SemanticQueryEntityType } from '@spotto/contract';
2
- /**
3
- * What an organisation's catalogue looks like to this package.
4
- *
5
- * These are NOT wire shapes — the wire contract lives in `@spotto/contract`.
6
- * This is the vocabulary a query is resolved AGAINST: which custom fields
7
- * exist, what type each one is, and (for the evaluator) the type documents
8
- * whose values an asset inherits.
9
- */
10
- export interface SemanticFieldDef {
11
- /** The field's id — custom-field matching is by `_id`, not name. */
12
- id: string;
13
- name: string;
14
- dataType: FieldDataType;
15
- /** Dropdown options — an eq value must match one exactly or the query silently returns nothing. */
16
- options?: string[];
17
- }
18
- /** A resolved type-level field value, as materialised in `typeFieldValuesAll`. */
19
- export interface SemanticTypeFieldValue {
20
- _id?: string;
21
- name?: string;
22
- valueString?: string;
23
- valueInteger?: number;
24
- valueDecimal?: number;
25
- valueBoolean?: boolean;
26
- valueDate?: number;
27
- }
28
- export interface SemanticTypeDef {
29
- id: string;
30
- /** Pipe-delimited, pipe-terminated. Root type is "". */
31
- path: string;
32
- /** Inheritance already resolved by the platform. */
33
- typeFieldValuesAll: SemanticTypeFieldValue[];
34
- }
35
- /**
36
- * A NAMED record a condition can point at by name instead of by id.
37
- *
38
- * This is how the event vocabulary escapes the producer gap without repeating
39
- * its mistake. An id cannot be asked of a model — it would be invented, and an
40
- * invented id runs and matches nothing. A NAME can be asked for, but only if
41
- * it is resolved against real records and an unresolvable or ambiguous one
42
- * FAILS: the moment resolution silently picks a candidate, or falls back to a
43
- * regex, it becomes the same silent-wrong-rows problem wearing a friendlier
44
- * face.
45
- *
46
- * Safe here and not for assets purely because of cardinality. Users, readers
47
- * and actions are small named catalogues that fit in a prompt and resolve
48
- * unambiguously; assets number in the thousands and share name stems
49
- * ("BC-A1" is a prefix of "BC-A10").
50
- */
51
- export interface SemanticNamedRef {
52
- id: string;
53
- name: string;
54
- /** Shown to a user in a suggestion when the name does not resolve. */
55
- label?: string;
56
- }
57
- /**
58
- * What VALIDATION needs: field definitions, plus the named catalogues the
59
- * event vocabulary resolves against. Empty catalogues are legitimate — a
60
- * caller that never validates event conditions supplies none, and one that
61
- * does gets an honest "no one called that" rather than a match on nothing.
62
- */
63
- export interface SemanticFieldCatalogue {
64
- fields: SemanticFieldDef[];
65
- /** Organisation users — resolves `{type:'user', name}`. */
66
- users?: SemanticNamedRef[];
67
- /** Readers — resolves `{type:'reader', name}`. */
68
- readers?: SemanticNamedRef[];
69
- /** Form actions — resolves `{type:'action', name}`. */
70
- actions?: SemanticNamedRef[];
71
- }
72
- /**
73
- * What EVALUATION needs: the catalogue plus types, because matching a
74
- * type-level field value in memory means walking the asset's type document.
75
- * (The Mongo compiler gets the same values through a `$lookup` instead.)
76
- */
77
- export interface SemanticAccountSchema extends SemanticFieldCatalogue {
78
- types: SemanticTypeDef[];
79
- }
80
- export interface SemanticValidationIssue {
81
- path: string;
82
- code: string;
83
- message: string;
84
- suggestion?: string;
85
- }
86
- export declare class SemanticQueryValidationError extends Error {
87
- issues: SemanticValidationIssue[];
88
- constructor(issues: SemanticValidationIssue[]);
89
- }
90
- /**
91
- * Throw one validation issue — fail-fast, this package's contract (the issues
92
- * array shape exists for the wire; internally the FIRST problem is the
93
- * answer). One helper beside the error class it throws, so issue construction
94
- * cannot drift between layers.
95
- */
96
- export declare function failSemanticValidation(path: string, code: string, message: string, suggestion?: string): never;
97
- export interface SemanticCompileOptions {
98
- /**
99
- * Explicit — never sampled deeper than the entry point, so a run is
100
- * reproducible: the same query, catalogue, `now` and timezone always give
101
- * the same answer, whoever is asking.
102
- */
103
- now?: Date;
104
- /** IANA zone for resolving relative dates. */
105
- timeZone?: string;
106
- /**
107
- * Which entity's vocabulary applies. Defaults to `asset` — the only entity
108
- * that executes today, and what every existing caller means.
109
- */
110
- entityType?: SemanticQueryEntityType;
111
- }
1
+ import { FieldDataType, SemanticQueryEntityType } from '@spotto/contract';
2
+ /**
3
+ * What an organisation's catalogue looks like to this package.
4
+ *
5
+ * These are NOT wire shapes — the wire contract lives in `@spotto/contract`.
6
+ * This is the vocabulary a query is resolved AGAINST: which custom fields
7
+ * exist, what type each one is, and (for the evaluator) the type documents
8
+ * whose values an asset inherits.
9
+ */
10
+ export interface SemanticFieldDef {
11
+ /** The field's id — custom-field matching is by `_id`, not name. */
12
+ id: string;
13
+ name: string;
14
+ dataType: FieldDataType;
15
+ /** Dropdown options — an eq value must match one exactly or the query silently returns nothing. */
16
+ options?: string[];
17
+ }
18
+ /** A resolved type-level field value, as materialised in `typeFieldValuesAll`. */
19
+ export interface SemanticTypeFieldValue {
20
+ _id?: string;
21
+ name?: string;
22
+ valueString?: string;
23
+ valueInteger?: number;
24
+ valueDecimal?: number;
25
+ valueBoolean?: boolean;
26
+ valueDate?: number;
27
+ }
28
+ export interface SemanticTypeDef {
29
+ id: string;
30
+ /** Pipe-delimited, pipe-terminated. Root type is "". */
31
+ path: string;
32
+ /** Inheritance already resolved by the platform. */
33
+ typeFieldValuesAll: SemanticTypeFieldValue[];
34
+ }
35
+ /**
36
+ * A NAMED record a condition can point at by name instead of by id.
37
+ *
38
+ * This is how the event vocabulary escapes the producer gap without repeating
39
+ * its mistake. An id cannot be asked of a model — it would be invented, and an
40
+ * invented id runs and matches nothing. A NAME can be asked for, but only if
41
+ * it is resolved against real records and an unresolvable or ambiguous one
42
+ * FAILS: the moment resolution silently picks a candidate, or falls back to a
43
+ * regex, it becomes the same silent-wrong-rows problem wearing a friendlier
44
+ * face.
45
+ *
46
+ * Safe here and not for assets purely because of cardinality. Users, readers
47
+ * and actions are small named catalogues that fit in a prompt and resolve
48
+ * unambiguously; assets number in the thousands and share name stems
49
+ * ("BC-A1" is a prefix of "BC-A10").
50
+ */
51
+ export interface SemanticNamedRef {
52
+ id: string;
53
+ name: string;
54
+ /** Shown to a user in a suggestion when the name does not resolve. */
55
+ label?: string;
56
+ }
57
+ /**
58
+ * What VALIDATION needs: field definitions, plus the named catalogues the
59
+ * event vocabulary resolves against. Empty catalogues are legitimate — a
60
+ * caller that never validates event conditions supplies none, and one that
61
+ * does gets an honest "no one called that" rather than a match on nothing.
62
+ */
63
+ export interface SemanticFieldCatalogue {
64
+ fields: SemanticFieldDef[];
65
+ /** Organisation users — resolves `{type:'user', name}`. */
66
+ users?: SemanticNamedRef[];
67
+ /** Readers — resolves `{type:'reader', name}`. */
68
+ readers?: SemanticNamedRef[];
69
+ /** Form actions — resolves `{type:'action', name}`. */
70
+ actions?: SemanticNamedRef[];
71
+ }
72
+ /**
73
+ * What EVALUATION needs: the catalogue plus types, because matching a
74
+ * type-level field value in memory means walking the asset's type document.
75
+ * (The Mongo compiler gets the same values through a `$lookup` instead.)
76
+ */
77
+ export interface SemanticAccountSchema extends SemanticFieldCatalogue {
78
+ types: SemanticTypeDef[];
79
+ }
80
+ export interface SemanticValidationIssue {
81
+ path: string;
82
+ code: string;
83
+ message: string;
84
+ suggestion?: string;
85
+ }
86
+ export declare class SemanticQueryValidationError extends Error {
87
+ issues: SemanticValidationIssue[];
88
+ constructor(issues: SemanticValidationIssue[]);
89
+ }
90
+ /**
91
+ * Throw one validation issue — fail-fast, this package's contract (the issues
92
+ * array shape exists for the wire; internally the FIRST problem is the
93
+ * answer). One helper beside the error class it throws, so issue construction
94
+ * cannot drift between layers.
95
+ */
96
+ export declare function failSemanticValidation(path: string, code: string, message: string, suggestion?: string): never;
97
+ export interface SemanticCompileOptions {
98
+ /**
99
+ * Explicit — never sampled deeper than the entry point, so a run is
100
+ * reproducible: the same query, catalogue, `now` and timezone always give
101
+ * the same answer, whoever is asking.
102
+ */
103
+ now?: Date;
104
+ /** IANA zone for resolving relative dates. */
105
+ timeZone?: string;
106
+ /**
107
+ * Which entity's vocabulary applies. Defaults to `asset` — the only entity
108
+ * that executes today, and what every existing caller means.
109
+ */
110
+ entityType?: SemanticQueryEntityType;
111
+ }
package/dist/types.js CHANGED
@@ -1,24 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.failSemanticValidation = exports.SemanticQueryValidationError = void 0;
4
- class SemanticQueryValidationError extends Error {
5
- constructor(issues) {
6
- super(issues.map((i) => i.message).join('; '));
7
- this.issues = issues;
8
- this.name = 'SemanticQueryValidationError';
9
- }
10
- }
11
- exports.SemanticQueryValidationError = SemanticQueryValidationError;
12
- /**
13
- * Throw one validation issue — fail-fast, this package's contract (the issues
14
- * array shape exists for the wire; internally the FIRST problem is the
15
- * answer). One helper beside the error class it throws, so issue construction
16
- * cannot drift between layers.
17
- */
18
- function failSemanticValidation(path, code, message, suggestion) {
19
- throw new SemanticQueryValidationError([
20
- suggestion ? { path, code, message, suggestion } : { path, code, message },
21
- ]);
22
- }
23
- exports.failSemanticValidation = failSemanticValidation;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.failSemanticValidation = exports.SemanticQueryValidationError = void 0;
4
+ class SemanticQueryValidationError extends Error {
5
+ constructor(issues) {
6
+ super(issues.map((i) => i.message).join('; '));
7
+ this.issues = issues;
8
+ this.name = 'SemanticQueryValidationError';
9
+ }
10
+ }
11
+ exports.SemanticQueryValidationError = SemanticQueryValidationError;
12
+ /**
13
+ * Throw one validation issue — fail-fast, this package's contract (the issues
14
+ * array shape exists for the wire; internally the FIRST problem is the
15
+ * answer). One helper beside the error class it throws, so issue construction
16
+ * cannot drift between layers.
17
+ */
18
+ function failSemanticValidation(path, code, message, suggestion) {
19
+ throw new SemanticQueryValidationError([
20
+ suggestion ? { path, code, message, suggestion } : { path, code, message },
21
+ ]);
22
+ }
23
+ exports.failSemanticValidation = failSemanticValidation;
24
24
  //# sourceMappingURL=types.js.map
@@ -1,33 +1,33 @@
1
- import { FieldDataType, SemanticQuery } from '@spotto/contract';
2
- import { SemanticCompileOptions, SemanticFieldCatalogue, SemanticFieldDef, SemanticValidationIssue } from './types';
3
- /** The live storage slots. `valueBool` does not exist; the live key is `valueBoolean`. */
4
- export declare const SEMANTIC_VALUE_SLOT: Record<string, string>;
5
- /** Millisecond-timestamp fields, by condition type. `createdDate` uses the ObjectId. */
6
- export declare const SEMANTIC_TIMESTAMP_FIELD: Record<string, string>;
7
- /**
8
- * Find a field by name, case-insensitively — the one lookup both back-ends
9
- * use, so neither can resolve a name to a different field than the other.
10
- */
11
- export declare function findSemanticField(catalogue: SemanticFieldCatalogue, fieldName: unknown): SemanticFieldDef | undefined;
12
- /**
13
- * Turn a written value into the form its storage slot actually holds.
14
- *
15
- * Shared deliberately: the Mongo compiler and the in-memory evaluator must
16
- * compare against the SAME value, and this is where a numeric literal for a
17
- * text field, or a relative date for a DATE field, becomes one concrete thing.
18
- * Two copies of this would classify the same document differently.
19
- *
20
- * Throws a plain Error — the caller decides whether that is a validation issue
21
- * (it is, at the gate) or an impossible state (it is, after the gate).
22
- */
23
- export declare function coerceSemanticValue(value: unknown, dataType: FieldDataType, now: Date, tz: string): string | number | boolean;
24
- /**
25
- * Assert a query is valid, throwing `SemanticQueryValidationError` on the
26
- * first problem. This is the gate: a back-end may assume anything that passed
27
- * through it is safe to execute.
28
- */
29
- export declare function assertSemanticQuery(semanticQuery: SemanticQuery, catalogue: SemanticFieldCatalogue, opts?: SemanticCompileOptions): void;
30
- /** Validate without throwing. Empty array = valid. */
31
- export declare function validateSemanticQuery(semanticQuery: SemanticQuery, catalogue: SemanticFieldCatalogue, opts?: SemanticCompileOptions): SemanticValidationIssue[];
32
- /** True when any condition touches a custom field — both back-ends need to know. */
33
- export declare function queryUsesCustomFields(semanticQuery: SemanticQuery): boolean;
1
+ import { FieldDataType, SemanticQuery } from '@spotto/contract';
2
+ import { SemanticCompileOptions, SemanticFieldCatalogue, SemanticFieldDef, SemanticValidationIssue } from './types';
3
+ /** The live storage slots. `valueBool` does not exist; the live key is `valueBoolean`. */
4
+ export declare const SEMANTIC_VALUE_SLOT: Record<string, string>;
5
+ /** Millisecond-timestamp fields, by condition type. `createdDate` uses the ObjectId. */
6
+ export declare const SEMANTIC_TIMESTAMP_FIELD: Record<string, string>;
7
+ /**
8
+ * Find a field by name, case-insensitively — the one lookup both back-ends
9
+ * use, so neither can resolve a name to a different field than the other.
10
+ */
11
+ export declare function findSemanticField(catalogue: SemanticFieldCatalogue, fieldName: unknown): SemanticFieldDef | undefined;
12
+ /**
13
+ * Turn a written value into the form its storage slot actually holds.
14
+ *
15
+ * Shared deliberately: the Mongo compiler and the in-memory evaluator must
16
+ * compare against the SAME value, and this is where a numeric literal for a
17
+ * text field, or a relative date for a DATE field, becomes one concrete thing.
18
+ * Two copies of this would classify the same document differently.
19
+ *
20
+ * Throws a plain Error — the caller decides whether that is a validation issue
21
+ * (it is, at the gate) or an impossible state (it is, after the gate).
22
+ */
23
+ export declare function coerceSemanticValue(value: unknown, dataType: FieldDataType, now: Date, tz: string): string | number | boolean;
24
+ /**
25
+ * Assert a query is valid, throwing `SemanticQueryValidationError` on the
26
+ * first problem. This is the gate: a back-end may assume anything that passed
27
+ * through it is safe to execute.
28
+ */
29
+ export declare function assertSemanticQuery(semanticQuery: SemanticQuery, catalogue: SemanticFieldCatalogue, opts?: SemanticCompileOptions): void;
30
+ /** Validate without throwing. Empty array = valid. */
31
+ export declare function validateSemanticQuery(semanticQuery: SemanticQuery, catalogue: SemanticFieldCatalogue, opts?: SemanticCompileOptions): SemanticValidationIssue[];
32
+ /** True when any condition touches a custom field — both back-ends need to know. */
33
+ export declare function queryUsesCustomFields(semanticQuery: SemanticQuery): boolean;