@xdbml/parse 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast.d.ts +34 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/keywords.d.ts +3 -2
- package/dist/keywords.js +61 -3
- package/dist/module-resolver.d.ts +3 -3
- package/dist/module-resolver.js +32 -12
- package/dist/monarch.d.ts +1 -0
- package/dist/monarch.js +5 -1
- package/dist/name-resolver.d.ts +2 -2
- package/dist/name-resolver.js +131 -18
- package/dist/parser.d.ts +31 -7
- package/dist/parser.js +126 -19
- package/dist/supertypes.d.ts +110 -0
- package/dist/supertypes.js +526 -0
- package/package.json +1 -1
package/dist/ast.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface ExperimentalDeclaration {
|
|
|
38
38
|
features: string[];
|
|
39
39
|
span: Span;
|
|
40
40
|
}
|
|
41
|
-
export type TopLevelStatement = ProjectDeclaration | ContainerDeclaration | EntityDeclaration | TypeDeclaration | EdgeDeclaration | ViewDeclaration | EnumDeclaration | RefDeclaration | TablePartialDeclaration | TableGroupDeclaration | NoteDeclaration | TopLevelRecordsDeclaration | ModuleImportDirective;
|
|
41
|
+
export type TopLevelStatement = ProjectDeclaration | ContainerDeclaration | EntityDeclaration | TypeDeclaration | EdgeDeclaration | ViewDeclaration | EnumDeclaration | RefDeclaration | TablePartialDeclaration | TableGroupDeclaration | SupertypeGroupDeclaration | NoteDeclaration | TopLevelRecordsDeclaration | ModuleImportDirective;
|
|
42
42
|
export interface ProjectDeclaration {
|
|
43
43
|
kind: 'ProjectDeclaration';
|
|
44
44
|
name: string;
|
|
@@ -81,7 +81,11 @@ export interface FieldDeclaration {
|
|
|
81
81
|
export type TypeExpression = ScalarType | ObjectType | ArrayType | TupleType | MapType | SetType | UnionType | OneOfType | AnyOfType | AllOfType | JsonType | NamedTypeReference;
|
|
82
82
|
export interface ScalarType {
|
|
83
83
|
kind: 'ScalarType';
|
|
84
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* The base name: `int`, `varchar`, `decimal`, `objectId`, `Decimal128`,
|
|
86
|
+
* etc. May be qualified, `core.job_status`, when it names an Enum
|
|
87
|
+
* declared in a container (spec §16).
|
|
88
|
+
*/
|
|
85
89
|
name: string;
|
|
86
90
|
/** `(p, s)` parameters, e.g. for `decimal(19, 4)`. Numbers preserved as strings to keep round-trip fidelity. */
|
|
87
91
|
params?: string[];
|
|
@@ -182,7 +186,7 @@ export interface TypeDeclaration {
|
|
|
182
186
|
kind: 'TypeDeclaration';
|
|
183
187
|
name: string;
|
|
184
188
|
/**
|
|
185
|
-
* v0.2 scalar form (spec §
|
|
189
|
+
* v0.2 scalar form (spec §15.7): when present, this Type is an alias
|
|
186
190
|
* for the given type expression rather than an object-shaped record.
|
|
187
191
|
* Examples:
|
|
188
192
|
*
|
|
@@ -229,6 +233,11 @@ export interface EnumDeclaration {
|
|
|
229
233
|
kind: 'EnumDeclaration';
|
|
230
234
|
/** Source casing of `enum` or `Enum`; both are valid. */
|
|
231
235
|
keywordCasing: string;
|
|
236
|
+
/**
|
|
237
|
+
* May be `container.enum` form when declared schema-qualified at the
|
|
238
|
+
* top level (`enum core.job_status`); the resolver files it under that
|
|
239
|
+
* container, like an Enum declared inside the Container block.
|
|
240
|
+
*/
|
|
232
241
|
name: string;
|
|
233
242
|
values: EnumValue[];
|
|
234
243
|
span: Span;
|
|
@@ -339,6 +348,21 @@ export interface TableGroupDeclaration {
|
|
|
339
348
|
members: string[];
|
|
340
349
|
span: Span;
|
|
341
350
|
}
|
|
351
|
+
export interface SupertypeGroupDeclaration {
|
|
352
|
+
kind: 'SupertypeGroupDeclaration';
|
|
353
|
+
name: string;
|
|
354
|
+
settings: Setting[];
|
|
355
|
+
members: SupertypeGroupMember[];
|
|
356
|
+
span: Span;
|
|
357
|
+
}
|
|
358
|
+
export interface SupertypeGroupMember {
|
|
359
|
+
kind: 'SupertypeGroupMember';
|
|
360
|
+
/** Entity path as written: `Person` or `crm.Person`. */
|
|
361
|
+
name: string;
|
|
362
|
+
/** Member settings; `strategy` is the only recognized one (spec §12.7.4). */
|
|
363
|
+
settings: Setting[];
|
|
364
|
+
span: Span;
|
|
365
|
+
}
|
|
342
366
|
export interface PartialInjection {
|
|
343
367
|
kind: 'PartialInjection';
|
|
344
368
|
/** Identifier after the `~`. */
|
|
@@ -385,7 +409,7 @@ export interface ModuleImportDirective {
|
|
|
385
409
|
/**
|
|
386
410
|
* Directive mode:
|
|
387
411
|
* - `'reuse'`: transitive (visible to files that further import this file).
|
|
388
|
-
* The recommended default per spec §
|
|
412
|
+
* The recommended default per spec §27.4.
|
|
389
413
|
* - `'use'`: non-transitive (private to this file).
|
|
390
414
|
*/
|
|
391
415
|
mode: 'use' | 'reuse';
|
|
@@ -424,9 +448,10 @@ export type ImportSpec = {
|
|
|
424
448
|
* type Email as PII_Email
|
|
425
449
|
* field core.dim_customer.email
|
|
426
450
|
*
|
|
427
|
-
* The element type is one of the keywords from §
|
|
451
|
+
* The element type is one of the keywords from §27.3 (table, entity,
|
|
428
452
|
* collection, record, enum, tablepartial, note, schema, container,
|
|
429
|
-
* tablegroup, type, edge, view, diagramview, field
|
|
453
|
+
* tablegroup, type, edge, view, diagramview, field, and from v0.5
|
|
454
|
+
* supertypegroup). Stored lowercased.
|
|
430
455
|
*
|
|
431
456
|
* The source path follows xDBML's standard dotted form. Container.Entity
|
|
432
457
|
* for an entity inside a Container; Container.Entity.Field for a field.
|
|
@@ -447,7 +472,7 @@ export interface ImportItem {
|
|
|
447
472
|
* an entity, type, container, etc. clone). Field imports are not supported
|
|
448
473
|
* in P4 -- when they land, this type may grow to a wider union.
|
|
449
474
|
*
|
|
450
|
-
* Per spec §
|
|
475
|
+
* Per spec §27.6, the clone contains exactly the imported declaration(s),
|
|
451
476
|
* without surrounding wrappers from the source file. For an entity clone
|
|
452
477
|
* the content is the EntityDeclaration alone (no container wrapper); for a
|
|
453
478
|
* container clone the content is the ContainerDeclaration including its
|
|
@@ -459,7 +484,7 @@ export interface CloneBlock {
|
|
|
459
484
|
* Statements that the importing file pulls in from the source. Most are
|
|
460
485
|
* top-level shapes (Entity, Type, Enum, Container, etc.). The one
|
|
461
486
|
* exception is `FieldDeclaration`: when the parent directive imports
|
|
462
|
-
* one or more fields via `field <path>` items (spec §
|
|
487
|
+
* one or more fields via `field <path>` items (spec §27.8), each field
|
|
463
488
|
* appears here as a bare FieldDeclaration with no entity wrapper.
|
|
464
489
|
* The `flatten()` pass lifts each bare field into a synthetic
|
|
465
490
|
* TypeDeclaration at file scope so downstream consumers see a normal
|
|
@@ -545,7 +570,7 @@ export interface ParseOptions {
|
|
|
545
570
|
* Because this reader is synchronous, a host that supports remote sources
|
|
546
571
|
* must return the fetched text from a cache it populated beforehand. The
|
|
547
572
|
* network fetch, and its SSRF / redirect / size / timeout obligations
|
|
548
|
-
* (spec §
|
|
573
|
+
* (spec §27.14.5), live in the host's resolver, not in the parser.
|
|
549
574
|
*
|
|
550
575
|
* If absent, reference-only directives fall back to the P4 rejection
|
|
551
576
|
* with a clear "no resolver available" message. Clone-block-bearing
|
package/dist/index.d.ts
CHANGED
|
@@ -27,13 +27,15 @@
|
|
|
27
27
|
export * from './ast.ts';
|
|
28
28
|
export { tokenize, TokenKind, LexError } from './lexer.ts';
|
|
29
29
|
export type { Token } from './lexer.ts';
|
|
30
|
-
export { parse, Parser, ParseError } from './parser.ts';
|
|
30
|
+
export { parse, Parser, ParseError, SUPPORTED_XDBML_VERSION, compareVersions } from './parser.ts';
|
|
31
31
|
export { flatten } from './module-resolver.ts';
|
|
32
32
|
export { classifyModuleSource, isUrlKey, ModuleSourceError, } from './module-resolver.ts';
|
|
33
33
|
export type { ModuleSource } from './module-resolver.ts';
|
|
34
34
|
export { resolveNames, SymbolTable } from './name-resolver.ts';
|
|
35
35
|
export { FOREIGN_MASTER_FLAG, checkRelationships, hasForeignMasterFlag, isForeignMaster, pathToString, refChildEndpoint, refParentEndpoint, relationshipType, versionAtLeast, CONSTRAINT_TYPES, V04_RELATIONSHIP_SETTINGS, constraintType, entityNames, isEntityLevelEndpoint, isUndirected, } from './relationships.ts';
|
|
36
36
|
export type { RelationshipType, ConstraintType } from './relationships.ts';
|
|
37
|
+
export { SUPERTYPE_GROUP_VALUES, canonicalSupertypeGroupValue, checkSupertypeGroups, resolveSupertypeGroups, subtypeStrategy, supertypeChains, supertypeGroupSettings, } from './supertypes.ts';
|
|
38
|
+
export type { Completeness, Exclusivity, MaterializationStrategy, MergeOption, ResolvedSupertypeGroup, SupertypeGroupSettings, SupertypeGroupValueSetting, } from './supertypes.ts';
|
|
37
39
|
export type { Diagnostic, DiagnosticCode, ResolutionResult, SymbolEntry, SymbolKind, } from './name-resolver.ts';
|
|
38
40
|
export { xdbmlLanguageConfig, xdbmlMonarchTokensProvider, } from './monarch.ts';
|
|
39
41
|
export type { XDbmlLanguageConfiguration, XDbmlMonarchLanguage, } from './monarch.ts';
|
package/dist/index.js
CHANGED
|
@@ -26,9 +26,10 @@
|
|
|
26
26
|
*/
|
|
27
27
|
export * from "./ast.js";
|
|
28
28
|
export { tokenize, TokenKind, LexError } from "./lexer.js";
|
|
29
|
-
export { parse, Parser, ParseError } from "./parser.js";
|
|
29
|
+
export { parse, Parser, ParseError, SUPPORTED_XDBML_VERSION, compareVersions } from "./parser.js";
|
|
30
30
|
export { flatten } from "./module-resolver.js";
|
|
31
31
|
export { classifyModuleSource, isUrlKey, ModuleSourceError, } from "./module-resolver.js";
|
|
32
32
|
export { resolveNames, SymbolTable } from "./name-resolver.js";
|
|
33
33
|
export { FOREIGN_MASTER_FLAG, checkRelationships, hasForeignMasterFlag, isForeignMaster, pathToString, refChildEndpoint, refParentEndpoint, relationshipType, versionAtLeast, CONSTRAINT_TYPES, V04_RELATIONSHIP_SETTINGS, constraintType, entityNames, isEntityLevelEndpoint, isUndirected, } from "./relationships.js";
|
|
34
|
+
export { SUPERTYPE_GROUP_VALUES, canonicalSupertypeGroupValue, checkSupertypeGroups, resolveSupertypeGroups, subtypeStrategy, supertypeChains, supertypeGroupSettings, } from "./supertypes.js";
|
|
34
35
|
export { xdbmlLanguageConfig, xdbmlMonarchTokensProvider, } from "./monarch.js";
|
package/dist/keywords.d.ts
CHANGED
|
@@ -33,13 +33,14 @@ export declare const ENTITY_KEYWORDS: readonly ["table", "entity", "collection",
|
|
|
33
33
|
* The full set of declaration keywords. Includes containers,
|
|
34
34
|
* entities, and other top-level constructs.
|
|
35
35
|
*/
|
|
36
|
-
export declare const DECLARATION_KEYWORDS: readonly ["project", "container", "schema", "database", "keyspace", "namespace", "dataset", "bucket", "table", "entity", "collection", "record", "type", "edge", "view", "enum", "ref", "note", "tablepartial", "tablegroup", "diagramview"];
|
|
36
|
+
export declare const DECLARATION_KEYWORDS: readonly ["project", "container", "schema", "database", "keyspace", "namespace", "dataset", "bucket", "table", "entity", "collection", "record", "type", "edge", "view", "enum", "ref", "note", "tablepartial", "tablegroup", "supertypegroup", "diagramview"];
|
|
37
37
|
export declare const STRUCTURAL_TYPE_KEYWORDS: readonly ["object", "struct", "array", "list", "map", "dict", "dictionary", "set", "json", "jsonb", "variant"];
|
|
38
38
|
export declare const POLYMORPHISM_KEYWORDS: readonly ["union", "oneof", "anyof", "allof"];
|
|
39
39
|
export declare const SCALAR_TYPES: readonly ["tinyint", "smallint", "mediumint", "int", "integer", "bigint", "int32", "int64", "float", "double", "decimal", "dec", "numeric", "real", "bit", "bool", "boolean", "char", "varchar", "varchar2", "nvarchar", "nvarchar2", "nchar", "text", "mediumtext", "longtext", "string", "ntext", "binary", "varbinary", "blob", "mediumblob", "longblob", "tinyblob", "tinytext", "json", "jsonb", "variant", "xml", "date", "time", "datetime", "datetime2", "timestamp", "timestamptz", "year", "uuid", "inet6", "money", "smallmoney", "enum"];
|
|
40
40
|
export declare const BSON_TYPES: readonly ["objectid", "decimal128", "bindata", "minkey", "maxkey", "symbol", "regex", "long", "double"];
|
|
41
|
+
export declare const TARGET_NATIVE_TYPES: readonly ["number", "binary_float", "binary_double", "clob", "nclob", "bfile", "raw", "rowid", "urowid", "xmltype", "sdo_geometry", "interval", "serial", "smallserial", "bigserial", "serial2", "serial4", "serial8", "int2", "int4", "int8", "float4", "float8", "bytea", "citext", "inet", "cidr", "macaddr", "macaddr8", "tsvector", "tsquery", "hstore", "jsonpath", "timetz", "varbit", "int4range", "int8range", "numrange", "tsrange", "tstzrange", "daterange", "uniqueidentifier", "datetimeoffset", "smalldatetime", "rowversion", "hierarchyid", "sql_variant", "timestamp_ntz", "timestamp_ltz", "timestamp_tz", "vector", "float64", "bignumeric", "bigdecimal", "bytes", "geometry", "geography", "ascii", "varint", "timeuuid", "uint32", "uint64", "sint32", "sint64", "fixed32", "fixed64", "sfixed32", "sfixed64", "uint8", "uint16", "int16", "float32"];
|
|
41
42
|
export declare const SETTING_FLAGS: readonly ["pk", "primary", "key", "unique", "null", "not", "required", "increment", "inactive", "foreign_master"];
|
|
42
|
-
export declare const SETTING_KEYS: readonly ["note", "default", "ref", "name", "color", "headercolor", "as", "check", "type", "target", "targets", "database_type", "source", "source_cardinality", "target_cardinality", "min_source", "max_source", "min_target", "max_target", "undirected", "source_role", "target_role", "source_verb", "target_verb", "constraint_type", "discriminator", "source_query", "materialized", "refresh_schedule", "refresh_on", "source_database", "storage_options", "pattern", "format", "minlength", "maxlength", "minimum", "maximum", "exclusiveminimum", "exclusivemaximum", "multipleof", "minitems", "maxitems", "uniqueitems", "minproperties", "maxproperties", "synonyms", "business_term", "granularity", "tags", "delete", "update", "indexes", "checks", "replication", "location", "default_charset", "cloned_at"];
|
|
43
|
+
export declare const SETTING_KEYS: readonly ["note", "default", "ref", "name", "color", "headercolor", "as", "check", "type", "target", "targets", "database_type", "source", "source_cardinality", "target_cardinality", "min_source", "max_source", "min_target", "max_target", "undirected", "source_role", "target_role", "source_verb", "target_verb", "constraint_type", "discriminator", "supertype", "completeness", "exclusivity", "strategy", "merge", "source_query", "materialized", "refresh_schedule", "refresh_on", "source_database", "storage_options", "pattern", "format", "minlength", "maxlength", "minimum", "maximum", "exclusiveminimum", "exclusivemaximum", "multipleof", "minitems", "maxitems", "uniqueitems", "minproperties", "maxproperties", "synonyms", "business_term", "granularity", "tags", "delete", "update", "indexes", "checks", "replication", "location", "default_charset", "cloned_at"];
|
|
43
44
|
export declare const GRANULARITY_VALUES: readonly ["year", "quarter", "month", "week", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"];
|
|
44
45
|
export declare const DIRECTIVE_KEYWORDS: readonly ["xdbml", "experimental"];
|
|
45
46
|
export declare const MODULE_KEYWORDS: readonly ["use", "reuse", "from", "as"];
|
package/dist/keywords.js
CHANGED
|
@@ -66,6 +66,7 @@ export const DECLARATION_KEYWORDS = [
|
|
|
66
66
|
'note',
|
|
67
67
|
'tablepartial',
|
|
68
68
|
'tablegroup',
|
|
69
|
+
'supertypegroup',
|
|
69
70
|
'diagramview',
|
|
70
71
|
];
|
|
71
72
|
/* -------------------------------------------------------------------------
|
|
@@ -97,9 +98,15 @@ export const POLYMORPHISM_KEYWORDS = [
|
|
|
97
98
|
/* -------------------------------------------------------------------------
|
|
98
99
|
* Scalar and BSON types
|
|
99
100
|
*
|
|
100
|
-
* The parser accepts any identifier as a scalar type (open vocabulary
|
|
101
|
-
* so these lists
|
|
102
|
-
*
|
|
101
|
+
* The parser accepts any identifier as a scalar type (open vocabulary,
|
|
102
|
+
* spec §1.2 principle 4), so these lists never reject a type name.
|
|
103
|
+
* They serve two purposes: themes color them under `storage.type`
|
|
104
|
+
* (TextMate) or `type` (Monarch), and the name resolver treats them as
|
|
105
|
+
* built-in names, which a Named Type cannot shadow (spec §15.2).
|
|
106
|
+
* Adding a name here therefore changes resolution as well as color: a
|
|
107
|
+
* document declaring `Type <that name>` would stop resolving to its own
|
|
108
|
+
* Type. Target-native names that only need color go in
|
|
109
|
+
* TARGET_NATIVE_TYPES below.
|
|
103
110
|
* ----------------------------------------------------------------------- */
|
|
104
111
|
export const SCALAR_TYPES = [
|
|
105
112
|
// Integers
|
|
@@ -138,6 +145,51 @@ export const BSON_TYPES = [
|
|
|
138
145
|
'long',
|
|
139
146
|
'double',
|
|
140
147
|
];
|
|
148
|
+
/* -------------------------------------------------------------------------
|
|
149
|
+
* Target-native types (highlighting only)
|
|
150
|
+
*
|
|
151
|
+
* Common type names of specific targets, colored like SCALAR_TYPES so
|
|
152
|
+
* that a physical model reads the same in the editor as a generic one.
|
|
153
|
+
* Unlike SCALAR_TYPES, these are not built-in names: the resolver
|
|
154
|
+
* passes them through like any other target-native name, and a Named
|
|
155
|
+
* Type or Enum may be declared under one of them.
|
|
156
|
+
*
|
|
157
|
+
* Coloring is position-independent (Monarch and TextMate both match
|
|
158
|
+
* the bare word), so a field named after a listed type is colored as a
|
|
159
|
+
* type too. Generic words that often name fields -- `point`, `line`,
|
|
160
|
+
* `box`, `path`, `circle`, `image`, `counter`, `duration`, `name` --
|
|
161
|
+
* are left out for that reason. The list is a convenience, not a
|
|
162
|
+
* vocabulary: a name missing from it is still a valid type.
|
|
163
|
+
* ----------------------------------------------------------------------- */
|
|
164
|
+
export const TARGET_NATIVE_TYPES = [
|
|
165
|
+
// Oracle
|
|
166
|
+
'number', 'binary_float', 'binary_double', 'clob', 'nclob', 'bfile',
|
|
167
|
+
'raw', 'rowid', 'urowid', 'xmltype', 'sdo_geometry',
|
|
168
|
+
// Oracle, PostgreSQL, BigQuery, Databricks
|
|
169
|
+
'interval',
|
|
170
|
+
// PostgreSQL
|
|
171
|
+
'serial', 'smallserial', 'bigserial', 'serial2', 'serial4', 'serial8',
|
|
172
|
+
'int2', 'int4', 'int8', 'float4', 'float8', 'bytea', 'citext',
|
|
173
|
+
'inet', 'cidr', 'macaddr', 'macaddr8', 'tsvector', 'tsquery', 'hstore',
|
|
174
|
+
'jsonpath', 'timetz', 'varbit',
|
|
175
|
+
'int4range', 'int8range', 'numrange', 'tsrange', 'tstzrange', 'daterange',
|
|
176
|
+
// SQL Server
|
|
177
|
+
'uniqueidentifier', 'datetimeoffset', 'smalldatetime', 'rowversion',
|
|
178
|
+
'hierarchyid', 'sql_variant',
|
|
179
|
+
// Snowflake (plus `number`, `interval`, `geography`, `geometry`)
|
|
180
|
+
'timestamp_ntz', 'timestamp_ltz', 'timestamp_tz', 'vector',
|
|
181
|
+
// BigQuery, Avro, Protobuf
|
|
182
|
+
'float64', 'bignumeric', 'bigdecimal', 'bytes',
|
|
183
|
+
// Spatial, across several targets
|
|
184
|
+
'geometry', 'geography',
|
|
185
|
+
// Cassandra
|
|
186
|
+
'ascii', 'varint', 'timeuuid',
|
|
187
|
+
// Protobuf
|
|
188
|
+
'uint32', 'uint64', 'sint32', 'sint64',
|
|
189
|
+
'fixed32', 'fixed64', 'sfixed32', 'sfixed64',
|
|
190
|
+
// ClickHouse
|
|
191
|
+
'uint8', 'uint16', 'int16', 'float32',
|
|
192
|
+
];
|
|
141
193
|
/* -------------------------------------------------------------------------
|
|
142
194
|
* Settings vocabulary
|
|
143
195
|
*
|
|
@@ -196,6 +248,12 @@ export const SETTING_KEYS = [
|
|
|
196
248
|
'target_verb',
|
|
197
249
|
'constraint_type',
|
|
198
250
|
'discriminator',
|
|
251
|
+
// v0.5 supertype groups (spec 12.2); `discriminator` is listed above
|
|
252
|
+
'supertype',
|
|
253
|
+
'completeness',
|
|
254
|
+
'exclusivity',
|
|
255
|
+
'strategy',
|
|
256
|
+
'merge',
|
|
199
257
|
'source_query',
|
|
200
258
|
'materialized',
|
|
201
259
|
'refresh_schedule',
|
|
@@ -30,13 +30,13 @@ import type { CloneBlock, ModuleImportDirective, ParseOptions, XDbmlDocument } f
|
|
|
30
30
|
*
|
|
31
31
|
* Inside a Container body, each `ModuleImportDirective` is replaced by its
|
|
32
32
|
* `clone.statements` as `ContainerBodyItem`s. Note that the spec table in
|
|
33
|
-
* §
|
|
33
|
+
* §27.6 guarantees that clone-block content for entity/edge/view/enum
|
|
34
34
|
* imports is shape-compatible with `ContainerBodyItem`; other shapes
|
|
35
35
|
* (e.g., a TablePartial clone inside a Container directive) would be
|
|
36
36
|
* semantically invalid per the spec and would surface as a downstream
|
|
37
37
|
* type error rather than being caught here.
|
|
38
38
|
*
|
|
39
|
-
* Field-level imports (spec §
|
|
39
|
+
* Field-level imports (spec §27.8) get a special transform: the clone
|
|
40
40
|
* block holds a bare `FieldDeclaration`, which `flatten()` lifts into a
|
|
41
41
|
* synthetic `TypeDeclaration` at file scope. Downstream consumers see
|
|
42
42
|
* a normal Named Type and can use it as a field type without learning
|
|
@@ -59,7 +59,7 @@ export type ParseFn = (source: string, options: ParseOptions, resolutionStack: R
|
|
|
59
59
|
* - `kind: 'resolved'` -- the file was opened, parsed, and a clone
|
|
60
60
|
* block was synthesized
|
|
61
61
|
* - `kind: 'cycle'` -- the resolution chain already contains this
|
|
62
|
-
* file; per spec §
|
|
62
|
+
* file; per spec §27.15 cycles are allowed, so we return an empty
|
|
63
63
|
* clone block and let name resolution (P6+) handle the actual
|
|
64
64
|
* cross-file linking
|
|
65
65
|
* - `kind: 'no-resolver'` -- no `readFile` was supplied; caller should
|
package/dist/module-resolver.js
CHANGED
|
@@ -30,13 +30,13 @@ import { SCALAR_TYPES, BSON_TYPES } from "./keywords.js";
|
|
|
30
30
|
*
|
|
31
31
|
* Inside a Container body, each `ModuleImportDirective` is replaced by its
|
|
32
32
|
* `clone.statements` as `ContainerBodyItem`s. Note that the spec table in
|
|
33
|
-
* §
|
|
33
|
+
* §27.6 guarantees that clone-block content for entity/edge/view/enum
|
|
34
34
|
* imports is shape-compatible with `ContainerBodyItem`; other shapes
|
|
35
35
|
* (e.g., a TablePartial clone inside a Container directive) would be
|
|
36
36
|
* semantically invalid per the spec and would surface as a downstream
|
|
37
37
|
* type error rather than being caught here.
|
|
38
38
|
*
|
|
39
|
-
* Field-level imports (spec §
|
|
39
|
+
* Field-level imports (spec §27.8) get a special transform: the clone
|
|
40
40
|
* block holds a bare `FieldDeclaration`, which `flatten()` lifts into a
|
|
41
41
|
* synthetic `TypeDeclaration` at file scope. Downstream consumers see
|
|
42
42
|
* a normal Named Type and can use it as a field type without learning
|
|
@@ -92,11 +92,11 @@ function flattenTopLevel(stmt, out) {
|
|
|
92
92
|
*
|
|
93
93
|
* - For SCALAR fields (any TypeExpression that isn't ObjectType): the
|
|
94
94
|
* Type is in scalar form with `scalarBase = field.type`. Equivalent
|
|
95
|
-
* to the v0.2 scalar-Named-Type form (spec §
|
|
95
|
+
* to the v0.2 scalar-Named-Type form (spec §15.7).
|
|
96
96
|
*
|
|
97
97
|
* - For OBJECT-typed fields (`field foo object { ... }`): the Type is
|
|
98
98
|
* in object form with `body = field.type.fields`. Equivalent to the
|
|
99
|
-
* v0.1 object-Named-Type form (spec §
|
|
99
|
+
* v0.1 object-Named-Type form (spec §15).
|
|
100
100
|
*
|
|
101
101
|
* Other type shapes (Array, Map, Set, Tuple, Union, polymorphic types)
|
|
102
102
|
* are valid as `scalarBase` of a Type and pass through unchanged. The
|
|
@@ -225,7 +225,7 @@ export function resolveImport(directive, options, resolutionStack, depth, parseF
|
|
|
225
225
|
* import spec. Applies aliases by renaming the extracted declaration.
|
|
226
226
|
*
|
|
227
227
|
* For `ImportAll`: every TopLevelStatement except ProjectDeclaration
|
|
228
|
-
* (per spec §
|
|
228
|
+
* (per spec §27.4, Project declarations cannot be imported).
|
|
229
229
|
*
|
|
230
230
|
* For `ImportList`: each item is matched by element-type + source path.
|
|
231
231
|
* Items not found in the source produce nothing (silent for P5; a
|
|
@@ -234,7 +234,7 @@ export function resolveImport(directive, options, resolutionStack, depth, parseF
|
|
|
234
234
|
function extractImports(spec, sourceDoc) {
|
|
235
235
|
if (spec.kind === 'ImportAll') {
|
|
236
236
|
// ImportAll never matches field imports (the `*` form is for top-level
|
|
237
|
-
// declarations only per spec §
|
|
237
|
+
// declarations only per spec §27.2). Return the source's top-level
|
|
238
238
|
// statements minus Project.
|
|
239
239
|
return sourceDoc.statements
|
|
240
240
|
.filter((s) => s.kind !== 'ProjectDeclaration')
|
|
@@ -248,7 +248,7 @@ function extractImports(spec, sourceDoc) {
|
|
|
248
248
|
out.push(applyAlias(found, item));
|
|
249
249
|
}
|
|
250
250
|
// Silent skip on not-found. The spec leaves diagnostics to name
|
|
251
|
-
// resolution (§
|
|
251
|
+
// resolution (§27.13). In practice, users notice missing entities
|
|
252
252
|
// because their references downstream become unresolved.
|
|
253
253
|
}
|
|
254
254
|
return out;
|
|
@@ -276,6 +276,8 @@ function extractImports(spec, sourceDoc) {
|
|
|
276
276
|
* ViewDeclaration with matching name; supports dotted path.
|
|
277
277
|
* - 'tablegroup':
|
|
278
278
|
* TableGroupDeclaration with matching name (top-level only).
|
|
279
|
+
* - 'supertypegroup':
|
|
280
|
+
* SupertypeGroupDeclaration with matching name (top-level only, v0.5).
|
|
279
281
|
* - 'tablepartial':
|
|
280
282
|
* TablePartialDeclaration with matching name (top-level only).
|
|
281
283
|
* - 'note':
|
|
@@ -344,6 +346,12 @@ function findImportTarget(item, doc) {
|
|
|
344
346
|
if (item.elementType === 'tablegroup') {
|
|
345
347
|
return doc.statements.find((s) => s.kind === 'TableGroupDeclaration' && s.name === path);
|
|
346
348
|
}
|
|
349
|
+
// SupertypeGroup (spec §12, v0.5): top-level only, bare name. The group
|
|
350
|
+
// comes with its membership; its entities resolve in the importing
|
|
351
|
+
// document, by import or declaration, like TableGroup members.
|
|
352
|
+
if (item.elementType === 'supertypegroup') {
|
|
353
|
+
return doc.statements.find((s) => s.kind === 'SupertypeGroupDeclaration' && s.name === path);
|
|
354
|
+
}
|
|
347
355
|
if (item.elementType === 'tablepartial') {
|
|
348
356
|
return doc.statements.find((s) => s.kind === 'TablePartialDeclaration' && s.name === path);
|
|
349
357
|
}
|
|
@@ -382,8 +390,18 @@ function findImportTarget(item, doc) {
|
|
|
382
390
|
}
|
|
383
391
|
return undefined;
|
|
384
392
|
}
|
|
385
|
-
// Enum: top-level OR container-scoped.
|
|
393
|
+
// Enum: top-level OR container-scoped. A top-level Enum declared with
|
|
394
|
+
// a qualified name (`enum core.job_status`, the DBML form) matches its
|
|
395
|
+
// full dotted path and imports under its bare name, like the
|
|
396
|
+
// container-scoped form: the source container does not survive into
|
|
397
|
+
// the importing file (spec §27.16).
|
|
386
398
|
if (item.elementType === 'enum') {
|
|
399
|
+
if (segments.length > 1) {
|
|
400
|
+
const qualifiedTopLevel = doc.statements.find((s) => s.kind === 'EnumDeclaration' && s.name === path);
|
|
401
|
+
if (qualifiedTopLevel && qualifiedTopLevel.kind === 'EnumDeclaration') {
|
|
402
|
+
return { ...qualifiedTopLevel, name: segments[segments.length - 1] };
|
|
403
|
+
}
|
|
404
|
+
}
|
|
387
405
|
if (segments.length === 1) {
|
|
388
406
|
return doc.statements.find((s) => s.kind === 'EnumDeclaration' && s.name === segments[0]);
|
|
389
407
|
}
|
|
@@ -403,7 +421,7 @@ function findImportTarget(item, doc) {
|
|
|
403
421
|
* object types to find a FieldDeclaration in a referenced source document.
|
|
404
422
|
* Returns undefined when any segment fails to resolve.
|
|
405
423
|
*
|
|
406
|
-
* Path shapes accepted (per spec §
|
|
424
|
+
* Path shapes accepted (per spec §27.8):
|
|
407
425
|
* - `entity.field` -- top-level entity
|
|
408
426
|
* - `container.entity.field` -- container-qualified entity
|
|
409
427
|
* - `entity.field.sub` -- nested via ObjectType
|
|
@@ -594,6 +612,8 @@ function applyAlias(stmt, item) {
|
|
|
594
612
|
return { ...stmt, name: item.alias };
|
|
595
613
|
case 'TableGroupDeclaration':
|
|
596
614
|
return { ...stmt, name: item.alias };
|
|
615
|
+
case 'SupertypeGroupDeclaration':
|
|
616
|
+
return { ...stmt, name: item.alias };
|
|
597
617
|
case 'TablePartialDeclaration':
|
|
598
618
|
return { ...stmt, name: item.alias };
|
|
599
619
|
case 'NoteDeclaration':
|
|
@@ -605,7 +625,7 @@ function applyAlias(stmt, item) {
|
|
|
605
625
|
}
|
|
606
626
|
}
|
|
607
627
|
/* -------------------------------------------------------------------------
|
|
608
|
-
* Module source classification (spec §
|
|
628
|
+
* Module source classification (spec §27.14, "Remote module sources")
|
|
609
629
|
*
|
|
610
630
|
* A `from` source is recognized purely by its scheme. A source beginning
|
|
611
631
|
* with 'https://' is a remote (URL) source; anything else is a relative
|
|
@@ -617,7 +637,7 @@ function applyAlias(stmt, item) {
|
|
|
617
637
|
* This is pure, synchronous classification. The actual network fetch is
|
|
618
638
|
* delegated to ParseOptions.readFile (the host's resolver). The obligations
|
|
619
639
|
* on a fetcher (SSRF defenses, https-only redirects, size and time limits)
|
|
620
|
-
* live with that resolver, not here; see spec §
|
|
640
|
+
* live with that resolver, not here; see spec §27.14.5.
|
|
621
641
|
* ----------------------------------------------------------------------- */
|
|
622
642
|
/** Raised when a `from` source string is structurally disallowed. */
|
|
623
643
|
export class ModuleSourceError extends Error {
|
|
@@ -687,7 +707,7 @@ export function classifyModuleSource(from) {
|
|
|
687
707
|
* - A remote (https) source resolves to its normalized href. No '.xdbml'
|
|
688
708
|
* is appended (a raw-content URL may carry a query string).
|
|
689
709
|
* - A relative source whose importer is itself a remote module resolves
|
|
690
|
-
* against the importer's base URL per RFC 3986 (spec §
|
|
710
|
+
* against the importer's base URL per RFC 3986 (spec §27.14.1). A remote
|
|
691
711
|
* module therefore can never reach the local filesystem.
|
|
692
712
|
* - A relative source with a local importer resolves on the filesystem,
|
|
693
713
|
* exactly as in v0.2.
|
package/dist/monarch.d.ts
CHANGED
package/dist/monarch.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* dependency on consumers that just want to parse. The Monaco types
|
|
19
19
|
* are structurally compatible -- the consumer casts at the boundary.
|
|
20
20
|
*/
|
|
21
|
-
import { CONTAINER_KEYWORDS, ENTITY_KEYWORDS, DECLARATION_KEYWORDS, STRUCTURAL_TYPE_KEYWORDS, POLYMORPHISM_KEYWORDS, SCALAR_TYPES, BSON_TYPES, SETTING_FLAGS, SETTING_KEYS, GRANULARITY_VALUES, } from "./keywords.js";
|
|
21
|
+
import { CONTAINER_KEYWORDS, ENTITY_KEYWORDS, DECLARATION_KEYWORDS, STRUCTURAL_TYPE_KEYWORDS, POLYMORPHISM_KEYWORDS, SCALAR_TYPES, BSON_TYPES, TARGET_NATIVE_TYPES, SETTING_FLAGS, SETTING_KEYS, GRANULARITY_VALUES, } from "./keywords.js";
|
|
22
22
|
/* -------------------------------------------------------------------------
|
|
23
23
|
* Language configuration
|
|
24
24
|
* ----------------------------------------------------------------------- */
|
|
@@ -102,6 +102,9 @@ export const xdbmlMonarchTokensProvider = {
|
|
|
102
102
|
scalarTypes: [...SCALAR_TYPES],
|
|
103
103
|
// BSON / document-store types
|
|
104
104
|
bsonTypes: [...BSON_TYPES],
|
|
105
|
+
// Target-native types (Oracle `number`, PostgreSQL `serial`, ...):
|
|
106
|
+
// colored like scalar types, but not built-ins -- see keywords.ts.
|
|
107
|
+
nativeTypes: [...TARGET_NATIVE_TYPES],
|
|
105
108
|
// Bare-flag settings: `pk`, `unique`, `not null`, etc.
|
|
106
109
|
// `not null` and `primary key` are two words but tokenized one at a time
|
|
107
110
|
// here -- the highlighter colors each as `keyword.setting`.
|
|
@@ -165,6 +168,7 @@ export const xdbmlMonarchTokensProvider = {
|
|
|
165
168
|
'@decls': 'keyword.declaration',
|
|
166
169
|
'@scalarTypes': 'type',
|
|
167
170
|
'@bsonTypes': 'type.bson',
|
|
171
|
+
'@nativeTypes': 'type',
|
|
168
172
|
'@settingFlags': 'keyword.setting',
|
|
169
173
|
'@settingKeys': 'keyword.setting',
|
|
170
174
|
'@granularityValues': 'keyword.value',
|
package/dist/name-resolver.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Name resolution pass (spec §
|
|
2
|
+
* Name resolution pass (spec §27.10 / §27.15, parser batch P6).
|
|
3
3
|
*
|
|
4
4
|
* `resolveNames(doc)` walks an xDBML document (the flattened view; clone
|
|
5
5
|
* blocks have been merged) and produces:
|
|
@@ -67,7 +67,7 @@ export interface SymbolEntry {
|
|
|
67
67
|
* Stable diagnostic code. Tooling can match on these to filter or style
|
|
68
68
|
* messages without parsing the human-readable text.
|
|
69
69
|
*/
|
|
70
|
-
export type DiagnosticCode = 'duplicate-declaration' | 'unresolved-type' | 'unresolved-entity' | 'unresolved-field' | 'unresolved-partial' | 'unresolved-tablegroup-member' | 'unresolved-records-entity' | 'unresolved-records-column' | 'empty-import' | 'invalid-nested-path' | 'foreign-master-composite' | 'foreign-master-duplicate-child' | 'foreign-master-without-ref' | 'construct-requires-version' | 'ambiguous-ref-endpoint' | 'invalid-constraint-type' | 'constraint-type-on-foreign-master' | 'invalid-undirected' | 'entity-level-many-to-many';
|
|
70
|
+
export type DiagnosticCode = 'duplicate-declaration' | 'unresolved-type' | 'possible-type-typo' | 'unresolved-entity' | 'unresolved-field' | 'unresolved-partial' | 'unresolved-tablegroup-member' | 'unresolved-records-entity' | 'unresolved-records-column' | 'empty-import' | 'invalid-nested-path' | 'foreign-master-composite' | 'foreign-master-duplicate-child' | 'foreign-master-without-ref' | 'construct-requires-version' | 'ambiguous-ref-endpoint' | 'invalid-constraint-type' | 'constraint-type-on-foreign-master' | 'invalid-undirected' | 'entity-level-many-to-many' | 'missing-supertype' | 'unresolved-supertype-group-member' | 'invalid-supertype-group-value' | 'duplicate-subtype' | 'supertype-is-subtype' | 'subtype-in-multiple-groups' | 'supertype-cycle' | 'supertype-attribute-redeclared' | 'discriminator-on-overlapping-group' | 'merge-without-roll-up' | 'empty-supertype-group';
|
|
71
71
|
/**
|
|
72
72
|
* A single resolution diagnostic. Severity is currently always `error`,
|
|
73
73
|
* but the field is included to leave room for future warnings (e.g.,
|