@atscript/core 0.1.30 → 0.1.31

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/index.cjs CHANGED
@@ -3308,6 +3308,24 @@ else if (fnName === "now" && !["number", "string"].includes(baseType)) errors.pu
3308
3308
  }
3309
3309
  })
3310
3310
  },
3311
+ json: new AnnotationSpec({
3312
+ description: "Forces a field to be stored as a single JSON column instead of being flattened into separate columns. Use on nested object fields that should remain as JSON in the database.\n\n**Example:**\n```atscript\n@db.json\nmetadata: { key: string, value: string }\n```\n",
3313
+ nodeType: ["prop"],
3314
+ validate(token, _args, doc) {
3315
+ const errors = [];
3316
+ const field = token.parentNode;
3317
+ const definition$1 = field.getDefinition();
3318
+ if (definition$1 && isRef(definition$1)) {
3319
+ const unwound = doc.unwindType(definition$1.id, definition$1.chain);
3320
+ if (unwound && isPrimitive(unwound.def)) errors.push({
3321
+ message: "@db.json on a primitive field has no effect — primitive fields are already stored as scalar columns",
3322
+ severity: 2,
3323
+ range: token.range
3324
+ });
3325
+ }
3326
+ return errors;
3327
+ }
3328
+ }),
3311
3329
  ignore: new AnnotationSpec({
3312
3330
  description: "Excludes a field from the database schema. The field exists in the Atscript type but has no column in the DB.\n\n**Example:**\n```atscript\n@db.ignore\ndisplayName: string\n```\n",
3313
3331
  nodeType: ["prop"],
@@ -4328,6 +4346,251 @@ var BuildRepo = class {
4328
4346
  }
4329
4347
  };
4330
4348
 
4349
+ //#endregion
4350
+ //#region packages/core/src/flatten.ts
4351
+ function flattenInterfaceNode(doc, node) {
4352
+ const flatMap = new Map();
4353
+ const stack = new Set();
4354
+ let struct;
4355
+ if (node.hasExtends) struct = doc.resolveInterfaceExtends(node);
4356
+ if (!struct) struct = node.getDefinition();
4357
+ if (!struct || !isStructure(struct)) return flatMap;
4358
+ walkStructure(doc, struct, "", false, flatMap, stack);
4359
+ return flatMap;
4360
+ }
4361
+ /**
4362
+ * Checks whether a property has the `@db.json` annotation.
4363
+ *
4364
+ * NOTE: This is intentionally hardcoded to `db.json` (rather than being
4365
+ * configurable) because the flattening behavior is tightly coupled to DB
4366
+ * semantics — `@db.json` fields are stored as a single JSON column, so their
4367
+ * sub-paths must not appear in the flat map (they are not individually
4368
+ * queryable in filters or selectable in projections).
4369
+ */ function hasDbJsonAnnotation(prop) {
4370
+ if (!prop.annotations) return false;
4371
+ return prop.annotations.some((a) => a.name === "db.json");
4372
+ }
4373
+ function isPhantomNode(doc, def) {
4374
+ if (!def) return false;
4375
+ if (isPrimitive(def) && def.config.type === "phantom") return true;
4376
+ if (isRef(def)) {
4377
+ const unwound = doc.unwindType(def.id, def.chain);
4378
+ return !!(unwound?.def && isPrimitive(unwound.def) && unwound.def.config.type === "phantom");
4379
+ }
4380
+ return false;
4381
+ }
4382
+ function resolveNode(doc, def) {
4383
+ if (isRef(def)) {
4384
+ const ref$1 = def;
4385
+ const unwound = doc.unwindType(ref$1.id, ref$1.chain);
4386
+ if (unwound?.def) return resolveNode(unwound.doc, unwound.def);
4387
+ return undefined;
4388
+ }
4389
+ if (isInterface(def)) {
4390
+ const iface = def;
4391
+ let struct;
4392
+ if (iface.hasExtends) struct = doc.resolveInterfaceExtends(iface);
4393
+ if (!struct) struct = iface.getDefinition();
4394
+ if (struct) return {
4395
+ def: struct,
4396
+ doc
4397
+ };
4398
+ return undefined;
4399
+ }
4400
+ return {
4401
+ def,
4402
+ doc
4403
+ };
4404
+ }
4405
+ function isComplexNode(def) {
4406
+ return isStructure(def) || isArray(def) || isGroup(def) && def.entity !== "tuple";
4407
+ }
4408
+ function addToFlatMap(flatMap, path$5, descriptor) {
4409
+ const existing = flatMap.get(path$5);
4410
+ if (existing) {
4411
+ const group$1 = new SemanticGroup([existing.def, descriptor.def], "|");
4412
+ flatMap.set(path$5, {
4413
+ def: group$1,
4414
+ doc: existing.doc,
4415
+ optional: existing.optional || descriptor.optional,
4416
+ propNode: existing.propNode,
4417
+ intermediate: existing.intermediate && descriptor.intermediate ? true : undefined
4418
+ });
4419
+ } else flatMap.set(path$5, descriptor);
4420
+ }
4421
+ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack) {
4422
+ for (const [name, prop] of struct.props) {
4423
+ if (prop.token("identifier")?.pattern) continue;
4424
+ const propDef = prop.getDefinition();
4425
+ if (isPhantomNode(doc, propDef)) continue;
4426
+ const path$5 = prefix ? `${prefix}.${name}` : name;
4427
+ const optional = parentOptional || !!prop.token("optional");
4428
+ const dbJson = hasDbJsonAnnotation(prop);
4429
+ if (!propDef) {
4430
+ addToFlatMap(flatMap, path$5, {
4431
+ def: prop,
4432
+ doc,
4433
+ optional,
4434
+ propNode: prop
4435
+ });
4436
+ continue;
4437
+ }
4438
+ const resolved = resolveNode(doc, propDef);
4439
+ if (!resolved) {
4440
+ addToFlatMap(flatMap, path$5, {
4441
+ def: propDef,
4442
+ doc,
4443
+ optional,
4444
+ propNode: prop
4445
+ });
4446
+ continue;
4447
+ }
4448
+ if (dbJson) {
4449
+ addToFlatMap(flatMap, path$5, {
4450
+ def: resolved.def,
4451
+ doc: resolved.doc,
4452
+ optional,
4453
+ propNode: prop,
4454
+ dbJson: true
4455
+ });
4456
+ continue;
4457
+ }
4458
+ walkNode(resolved.doc, resolved.def, path$5, optional, prop, flatMap, stack);
4459
+ }
4460
+ }
4461
+ function walkNode(doc, def, path$5, optional, propNode, flatMap, stack) {
4462
+ if (stack.has(def)) {
4463
+ addToFlatMap(flatMap, path$5, {
4464
+ def,
4465
+ doc,
4466
+ optional,
4467
+ propNode
4468
+ });
4469
+ return;
4470
+ }
4471
+ stack.add(def);
4472
+ try {
4473
+ if (isStructure(def)) {
4474
+ addToFlatMap(flatMap, path$5, {
4475
+ def,
4476
+ doc,
4477
+ optional,
4478
+ propNode,
4479
+ intermediate: true
4480
+ });
4481
+ walkStructure(doc, def, path$5, optional, flatMap, stack);
4482
+ } else if (isArray(def)) {
4483
+ const elementDef = def.getDefinition();
4484
+ const resolvedElement = elementDef ? resolveNode(doc, elementDef) : undefined;
4485
+ const isComplexElement = resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def));
4486
+ if (isComplexElement) {
4487
+ addToFlatMap(flatMap, path$5, {
4488
+ def,
4489
+ doc,
4490
+ optional,
4491
+ propNode,
4492
+ intermediate: true
4493
+ });
4494
+ walkArrayElement(doc, def, path$5, optional, flatMap, stack);
4495
+ } else addToFlatMap(flatMap, path$5, {
4496
+ def,
4497
+ doc,
4498
+ optional,
4499
+ propNode
4500
+ });
4501
+ } else if (isGroup(def) && def.entity !== "structure") {
4502
+ const group$1 = def;
4503
+ if (group$1.op === "&") {
4504
+ const merged = doc.mergeIntersection(def);
4505
+ if (merged !== def && isStructure(merged)) {
4506
+ addToFlatMap(flatMap, path$5, {
4507
+ def: merged,
4508
+ doc,
4509
+ optional,
4510
+ propNode,
4511
+ intermediate: true
4512
+ });
4513
+ walkStructure(doc, merged, path$5, optional, flatMap, stack);
4514
+ } else addToFlatMap(flatMap, path$5, {
4515
+ def,
4516
+ doc,
4517
+ optional,
4518
+ propNode
4519
+ });
4520
+ } else if (group$1.op === "|") {
4521
+ const branches = group$1.unwrap();
4522
+ let hasComplexBranch = false;
4523
+ let hasLeafBranch = false;
4524
+ for (const branch of branches) {
4525
+ const resolved = resolveNode(doc, branch);
4526
+ if (resolved && isComplexNode(resolved.def)) hasComplexBranch = true;
4527
+ else hasLeafBranch = true;
4528
+ }
4529
+ if (hasComplexBranch) {
4530
+ if (hasLeafBranch) addToFlatMap(flatMap, path$5, {
4531
+ def,
4532
+ doc,
4533
+ optional,
4534
+ propNode
4535
+ });
4536
+ else addToFlatMap(flatMap, path$5, {
4537
+ def,
4538
+ doc,
4539
+ optional,
4540
+ propNode,
4541
+ intermediate: true
4542
+ });
4543
+ for (const branch of branches) {
4544
+ const resolved = resolveNode(doc, branch);
4545
+ if (resolved) walkBranch(resolved.doc, resolved.def, path$5, optional, flatMap, stack);
4546
+ }
4547
+ } else addToFlatMap(flatMap, path$5, {
4548
+ def,
4549
+ doc,
4550
+ optional,
4551
+ propNode
4552
+ });
4553
+ } else addToFlatMap(flatMap, path$5, {
4554
+ def,
4555
+ doc,
4556
+ optional,
4557
+ propNode
4558
+ });
4559
+ } else addToFlatMap(flatMap, path$5, {
4560
+ def,
4561
+ doc,
4562
+ optional,
4563
+ propNode
4564
+ });
4565
+ } finally {
4566
+ stack.delete(def);
4567
+ }
4568
+ }
4569
+ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack) {
4570
+ const elementDef = arrayNode.getDefinition();
4571
+ if (!elementDef) return;
4572
+ const resolved = resolveNode(doc, elementDef);
4573
+ if (!resolved) return;
4574
+ walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
4575
+ }
4576
+ /**
4577
+ * Walks a branch (union branch or array element) to collect sub-paths.
4578
+ * Does NOT add an entry for the branch itself — the parent already did that.
4579
+ */ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack) {
4580
+ if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack);
4581
+ else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack);
4582
+ else if (isGroup(def) && def.entity !== "structure") {
4583
+ const group$1 = def;
4584
+ if (group$1.op === "&") {
4585
+ const merged = doc.mergeIntersection(def);
4586
+ if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack);
4587
+ } else if (group$1.op === "|") for (const branch of group$1.unwrap()) {
4588
+ const resolved = resolveNode(doc, branch);
4589
+ if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
4590
+ }
4591
+ }
4592
+ }
4593
+
4331
4594
  //#endregion
4332
4595
  exports.$n = $n
4333
4596
  exports.AnnotationSpec = AnnotationSpec
@@ -4353,6 +4616,7 @@ exports.Token = Token
4353
4616
  exports.build = build
4354
4617
  exports.createAtscriptPlugin = createAtscriptPlugin
4355
4618
  exports.defineConfig = defineConfig
4619
+ exports.flattenInterfaceNode = flattenInterfaceNode
4356
4620
  exports.getRelPath = getRelPath
4357
4621
  exports.isAnnotate = isAnnotate
4358
4622
  exports.isAnnotationSpec = isAnnotationSpec
package/dist/index.d.ts CHANGED
@@ -781,5 +781,50 @@ declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsT
781
781
  declare function resolveAtscriptFromPath(from: string, id: string): string;
782
782
  declare function getRelPath(fromUri: string, toUri: string): string;
783
783
 
784
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
785
- export type { TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TSemanticToken };
784
+ /**
785
+ * Descriptor for a single field in the flattened interface map.
786
+ */
787
+ interface TFlatFieldDescriptor {
788
+ /** The resolved type definition node. */
789
+ def: SemanticNode;
790
+ /** The owning document (may differ from root for cross-file refs). */
791
+ doc: AtscriptDoc;
792
+ /** Whether the field is optional. */
793
+ optional: boolean;
794
+ /** The property node (for annotation access). Undefined for the root entry. */
795
+ propNode?: SemanticPropNode;
796
+ /**
797
+ * Whether this is an intermediate (non-leaf) path — a structure, array of structures,
798
+ * or union of only complex types. Intermediate entries should be typed as `never`
799
+ * in the rendered output to prevent meaningless `$eq` comparisons, while still
800
+ * appearing in autocomplete for `$select` and `$exists` checks.
801
+ */
802
+ intermediate?: boolean;
803
+ /** Whether this field has the `@db.json` annotation (stored as JSON string in DB). */
804
+ dbJson?: boolean;
805
+ }
806
+ /**
807
+ * Flattens an interface node into a map of dot-notation paths to their type descriptors.
808
+ *
809
+ * This utility exists to improve type-safety for filter expressions and `$select`/`$sort`
810
+ * operations in the DB layer. The generated `__flat` static property on `@db.table`
811
+ * interfaces uses this map to provide autocomplete and compile-time checks for
812
+ * dot-notation query paths.
813
+ *
814
+ * Walks the interface structure (including inherited props from `extends`) and collects
815
+ * all reachable field paths. Nested objects are recursed into, arrays are recursed through
816
+ * their element types, and unions/intersections are recursed through each branch (with
817
+ * colliding paths merged into union groups).
818
+ *
819
+ * Fields annotated with `@db.json` are treated as leaves — their sub-paths are NOT included,
820
+ * because `@db.json` fields are stored as a single JSON column in the database and their
821
+ * sub-paths are not individually queryable.
822
+ *
823
+ * @param doc - The document owning the interface node.
824
+ * @param node - The interface node to flatten.
825
+ * @returns A map of dot-separated paths to their field descriptors.
826
+ */
827
+ declare function flattenInterfaceNode(doc: AtscriptDoc, node: SemanticInterfaceNode): Map<string, TFlatFieldDescriptor>;
828
+
829
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
830
+ export type { TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TFlatFieldDescriptor, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TSemanticToken };
package/dist/index.mjs CHANGED
@@ -3284,6 +3284,24 @@ else if (fnName === "now" && !["number", "string"].includes(baseType)) errors.pu
3284
3284
  }
3285
3285
  })
3286
3286
  },
3287
+ json: new AnnotationSpec({
3288
+ description: "Forces a field to be stored as a single JSON column instead of being flattened into separate columns. Use on nested object fields that should remain as JSON in the database.\n\n**Example:**\n```atscript\n@db.json\nmetadata: { key: string, value: string }\n```\n",
3289
+ nodeType: ["prop"],
3290
+ validate(token, _args, doc) {
3291
+ const errors = [];
3292
+ const field = token.parentNode;
3293
+ const definition$1 = field.getDefinition();
3294
+ if (definition$1 && isRef(definition$1)) {
3295
+ const unwound = doc.unwindType(definition$1.id, definition$1.chain);
3296
+ if (unwound && isPrimitive(unwound.def)) errors.push({
3297
+ message: "@db.json on a primitive field has no effect — primitive fields are already stored as scalar columns",
3298
+ severity: 2,
3299
+ range: token.range
3300
+ });
3301
+ }
3302
+ return errors;
3303
+ }
3304
+ }),
3287
3305
  ignore: new AnnotationSpec({
3288
3306
  description: "Excludes a field from the database schema. The field exists in the Atscript type but has no column in the DB.\n\n**Example:**\n```atscript\n@db.ignore\ndisplayName: string\n```\n",
3289
3307
  nodeType: ["prop"],
@@ -4305,4 +4323,249 @@ var BuildRepo = class {
4305
4323
  };
4306
4324
 
4307
4325
  //#endregion
4308
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
4326
+ //#region packages/core/src/flatten.ts
4327
+ function flattenInterfaceNode(doc, node) {
4328
+ const flatMap = new Map();
4329
+ const stack = new Set();
4330
+ let struct;
4331
+ if (node.hasExtends) struct = doc.resolveInterfaceExtends(node);
4332
+ if (!struct) struct = node.getDefinition();
4333
+ if (!struct || !isStructure(struct)) return flatMap;
4334
+ walkStructure(doc, struct, "", false, flatMap, stack);
4335
+ return flatMap;
4336
+ }
4337
+ /**
4338
+ * Checks whether a property has the `@db.json` annotation.
4339
+ *
4340
+ * NOTE: This is intentionally hardcoded to `db.json` (rather than being
4341
+ * configurable) because the flattening behavior is tightly coupled to DB
4342
+ * semantics — `@db.json` fields are stored as a single JSON column, so their
4343
+ * sub-paths must not appear in the flat map (they are not individually
4344
+ * queryable in filters or selectable in projections).
4345
+ */ function hasDbJsonAnnotation(prop) {
4346
+ if (!prop.annotations) return false;
4347
+ return prop.annotations.some((a) => a.name === "db.json");
4348
+ }
4349
+ function isPhantomNode(doc, def) {
4350
+ if (!def) return false;
4351
+ if (isPrimitive(def) && def.config.type === "phantom") return true;
4352
+ if (isRef(def)) {
4353
+ const unwound = doc.unwindType(def.id, def.chain);
4354
+ return !!(unwound?.def && isPrimitive(unwound.def) && unwound.def.config.type === "phantom");
4355
+ }
4356
+ return false;
4357
+ }
4358
+ function resolveNode(doc, def) {
4359
+ if (isRef(def)) {
4360
+ const ref$1 = def;
4361
+ const unwound = doc.unwindType(ref$1.id, ref$1.chain);
4362
+ if (unwound?.def) return resolveNode(unwound.doc, unwound.def);
4363
+ return undefined;
4364
+ }
4365
+ if (isInterface(def)) {
4366
+ const iface = def;
4367
+ let struct;
4368
+ if (iface.hasExtends) struct = doc.resolveInterfaceExtends(iface);
4369
+ if (!struct) struct = iface.getDefinition();
4370
+ if (struct) return {
4371
+ def: struct,
4372
+ doc
4373
+ };
4374
+ return undefined;
4375
+ }
4376
+ return {
4377
+ def,
4378
+ doc
4379
+ };
4380
+ }
4381
+ function isComplexNode(def) {
4382
+ return isStructure(def) || isArray(def) || isGroup(def) && def.entity !== "tuple";
4383
+ }
4384
+ function addToFlatMap(flatMap, path$2, descriptor) {
4385
+ const existing = flatMap.get(path$2);
4386
+ if (existing) {
4387
+ const group$1 = new SemanticGroup([existing.def, descriptor.def], "|");
4388
+ flatMap.set(path$2, {
4389
+ def: group$1,
4390
+ doc: existing.doc,
4391
+ optional: existing.optional || descriptor.optional,
4392
+ propNode: existing.propNode,
4393
+ intermediate: existing.intermediate && descriptor.intermediate ? true : undefined
4394
+ });
4395
+ } else flatMap.set(path$2, descriptor);
4396
+ }
4397
+ function walkStructure(doc, struct, prefix, parentOptional, flatMap, stack) {
4398
+ for (const [name, prop] of struct.props) {
4399
+ if (prop.token("identifier")?.pattern) continue;
4400
+ const propDef = prop.getDefinition();
4401
+ if (isPhantomNode(doc, propDef)) continue;
4402
+ const path$2 = prefix ? `${prefix}.${name}` : name;
4403
+ const optional = parentOptional || !!prop.token("optional");
4404
+ const dbJson = hasDbJsonAnnotation(prop);
4405
+ if (!propDef) {
4406
+ addToFlatMap(flatMap, path$2, {
4407
+ def: prop,
4408
+ doc,
4409
+ optional,
4410
+ propNode: prop
4411
+ });
4412
+ continue;
4413
+ }
4414
+ const resolved = resolveNode(doc, propDef);
4415
+ if (!resolved) {
4416
+ addToFlatMap(flatMap, path$2, {
4417
+ def: propDef,
4418
+ doc,
4419
+ optional,
4420
+ propNode: prop
4421
+ });
4422
+ continue;
4423
+ }
4424
+ if (dbJson) {
4425
+ addToFlatMap(flatMap, path$2, {
4426
+ def: resolved.def,
4427
+ doc: resolved.doc,
4428
+ optional,
4429
+ propNode: prop,
4430
+ dbJson: true
4431
+ });
4432
+ continue;
4433
+ }
4434
+ walkNode(resolved.doc, resolved.def, path$2, optional, prop, flatMap, stack);
4435
+ }
4436
+ }
4437
+ function walkNode(doc, def, path$2, optional, propNode, flatMap, stack) {
4438
+ if (stack.has(def)) {
4439
+ addToFlatMap(flatMap, path$2, {
4440
+ def,
4441
+ doc,
4442
+ optional,
4443
+ propNode
4444
+ });
4445
+ return;
4446
+ }
4447
+ stack.add(def);
4448
+ try {
4449
+ if (isStructure(def)) {
4450
+ addToFlatMap(flatMap, path$2, {
4451
+ def,
4452
+ doc,
4453
+ optional,
4454
+ propNode,
4455
+ intermediate: true
4456
+ });
4457
+ walkStructure(doc, def, path$2, optional, flatMap, stack);
4458
+ } else if (isArray(def)) {
4459
+ const elementDef = def.getDefinition();
4460
+ const resolvedElement = elementDef ? resolveNode(doc, elementDef) : undefined;
4461
+ const isComplexElement = resolvedElement && (isStructure(resolvedElement.def) || isGroup(resolvedElement.def) && resolvedElement.def.entity !== "tuple" || isArray(resolvedElement.def));
4462
+ if (isComplexElement) {
4463
+ addToFlatMap(flatMap, path$2, {
4464
+ def,
4465
+ doc,
4466
+ optional,
4467
+ propNode,
4468
+ intermediate: true
4469
+ });
4470
+ walkArrayElement(doc, def, path$2, optional, flatMap, stack);
4471
+ } else addToFlatMap(flatMap, path$2, {
4472
+ def,
4473
+ doc,
4474
+ optional,
4475
+ propNode
4476
+ });
4477
+ } else if (isGroup(def) && def.entity !== "structure") {
4478
+ const group$1 = def;
4479
+ if (group$1.op === "&") {
4480
+ const merged = doc.mergeIntersection(def);
4481
+ if (merged !== def && isStructure(merged)) {
4482
+ addToFlatMap(flatMap, path$2, {
4483
+ def: merged,
4484
+ doc,
4485
+ optional,
4486
+ propNode,
4487
+ intermediate: true
4488
+ });
4489
+ walkStructure(doc, merged, path$2, optional, flatMap, stack);
4490
+ } else addToFlatMap(flatMap, path$2, {
4491
+ def,
4492
+ doc,
4493
+ optional,
4494
+ propNode
4495
+ });
4496
+ } else if (group$1.op === "|") {
4497
+ const branches = group$1.unwrap();
4498
+ let hasComplexBranch = false;
4499
+ let hasLeafBranch = false;
4500
+ for (const branch of branches) {
4501
+ const resolved = resolveNode(doc, branch);
4502
+ if (resolved && isComplexNode(resolved.def)) hasComplexBranch = true;
4503
+ else hasLeafBranch = true;
4504
+ }
4505
+ if (hasComplexBranch) {
4506
+ if (hasLeafBranch) addToFlatMap(flatMap, path$2, {
4507
+ def,
4508
+ doc,
4509
+ optional,
4510
+ propNode
4511
+ });
4512
+ else addToFlatMap(flatMap, path$2, {
4513
+ def,
4514
+ doc,
4515
+ optional,
4516
+ propNode,
4517
+ intermediate: true
4518
+ });
4519
+ for (const branch of branches) {
4520
+ const resolved = resolveNode(doc, branch);
4521
+ if (resolved) walkBranch(resolved.doc, resolved.def, path$2, optional, flatMap, stack);
4522
+ }
4523
+ } else addToFlatMap(flatMap, path$2, {
4524
+ def,
4525
+ doc,
4526
+ optional,
4527
+ propNode
4528
+ });
4529
+ } else addToFlatMap(flatMap, path$2, {
4530
+ def,
4531
+ doc,
4532
+ optional,
4533
+ propNode
4534
+ });
4535
+ } else addToFlatMap(flatMap, path$2, {
4536
+ def,
4537
+ doc,
4538
+ optional,
4539
+ propNode
4540
+ });
4541
+ } finally {
4542
+ stack.delete(def);
4543
+ }
4544
+ }
4545
+ function walkArrayElement(doc, arrayNode, prefix, parentOptional, flatMap, stack) {
4546
+ const elementDef = arrayNode.getDefinition();
4547
+ if (!elementDef) return;
4548
+ const resolved = resolveNode(doc, elementDef);
4549
+ if (!resolved) return;
4550
+ walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
4551
+ }
4552
+ /**
4553
+ * Walks a branch (union branch or array element) to collect sub-paths.
4554
+ * Does NOT add an entry for the branch itself — the parent already did that.
4555
+ */ function walkBranch(doc, def, prefix, parentOptional, flatMap, stack) {
4556
+ if (isStructure(def)) walkStructure(doc, def, prefix, parentOptional, flatMap, stack);
4557
+ else if (isArray(def)) walkArrayElement(doc, def, prefix, parentOptional, flatMap, stack);
4558
+ else if (isGroup(def) && def.entity !== "structure") {
4559
+ const group$1 = def;
4560
+ if (group$1.op === "&") {
4561
+ const merged = doc.mergeIntersection(def);
4562
+ if (isStructure(merged)) walkStructure(doc, merged, prefix, parentOptional, flatMap, stack);
4563
+ } else if (group$1.op === "|") for (const branch of group$1.unwrap()) {
4564
+ const resolved = resolveNode(doc, branch);
4565
+ if (resolved) walkBranch(resolved.doc, resolved.def, prefix, parentOptional, flatMap, stack);
4566
+ }
4567
+ }
4568
+ }
4569
+
4570
+ //#endregion
4571
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, flattenInterfaceNode, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",