@atscript/typescript 0.1.4 → 0.1.6

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/cli.cjs CHANGED
@@ -298,8 +298,9 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
298
298
  patterns.push(prop);
299
299
  continue;
300
300
  }
301
- if (this.isPhantomProp(prop.getDefinition())) {
302
- this.writeln(`// ${prop.id}: phantom`);
301
+ const phantomType = this.phantomPropType(prop.getDefinition());
302
+ if (phantomType) {
303
+ this.writeln(`// ${prop.id}: ${phantomType}`);
303
304
  continue;
304
305
  }
305
306
  const optional = !!prop.token("optional");
@@ -345,12 +346,6 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
345
346
  if (struct?.entity === "structure") this.renderStructure(struct, node.id);
346
347
  else this.writeln("{}");
347
348
  this.writeln();
348
- const nsPrefix = exported ? "export declare" : "declare";
349
- this.write(`${nsPrefix} namespace ${node.id} `);
350
- this.blockln("{}");
351
- this.writeln(`type DataType = ${node.id}`);
352
- this.popln();
353
- this.writeln();
354
349
  }
355
350
  renderType(node) {
356
351
  this.writeln();
@@ -377,12 +372,6 @@ else this.writeln("{}");
377
372
  } else {
378
373
  this.write(exported ? "export declare " : "declare ");
379
374
  this.writeln(`class ${node.id} extends ${targetName} {}`);
380
- const nsPrefix = exported ? "export declare" : "declare";
381
- this.write(`${nsPrefix} namespace ${node.id} `);
382
- this.blockln("{}");
383
- this.writeln(`type DataType = ${node.id}`);
384
- this.popln();
385
- this.writeln();
386
375
  }
387
376
  }
388
377
  renderTypeNamespace(node) {
@@ -401,23 +390,23 @@ else if ((0, __atscript_core.isGroup)(realDef)) typeDef = `TAtscriptTypeComplex<
401
390
  else if ((0, __atscript_core.isArray)(realDef)) typeDef = `TAtscriptTypeArray<${name}>`;
402
391
  else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
403
392
  }
404
- this.writeln(`type DataType = ${name}`);
405
393
  this.writeln(`const __is_atscript_annotated_type: true`);
406
394
  this.writeln(`const type: ${typeDef}`);
407
395
  this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
408
- this.writeln(`const validator: (opts?: Partial<TValidatorOptions>) => Validator<typeof ${name}, ${name}>`);
396
+ this.writeln(`const validator: (opts?: Partial<TValidatorOptions>) => Validator<typeof ${name}>`);
409
397
  if (resolveJsonSchemaMode(this.opts) === false) this.writeln("/** @deprecated JSON Schema support is disabled. Calling this method will throw a runtime error. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add `@emit.jsonSchema` annotation to individual interfaces. */");
410
398
  this.writeln("const toJsonSchema: () => any");
411
399
  this.popln();
412
400
  }
413
- isPhantomProp(def) {
414
- if (!def) return false;
415
- if ((0, __atscript_core.isPrimitive)(def) && def.id === "phantom") return true;
401
+ phantomPropType(def) {
402
+ if (!def) return undefined;
403
+ if ((0, __atscript_core.isPrimitive)(def) && def.config.type === "phantom") return def.id;
416
404
  if ((0, __atscript_core.isRef)(def)) {
417
- const unwound = this.doc.unwindType(def.id, def.chain)?.def;
418
- return (0, __atscript_core.isPrimitive)(unwound) && unwound.id === "phantom";
405
+ const ref = def;
406
+ const unwound = this.doc.unwindType(ref.id, ref.chain)?.def;
407
+ if ((0, __atscript_core.isPrimitive)(unwound) && unwound.config.type === "phantom") return ref.hasChain ? `${ref.id}.${ref.chain.map((c) => c.text).join(".")}` : ref.id;
419
408
  }
420
- return false;
409
+ return undefined;
421
410
  }
422
411
  isTypeTarget(name, doc) {
423
412
  const d = doc || this.doc;
@@ -1172,7 +1161,7 @@ else {
1172
1161
  case "primitive": {
1173
1162
  const prim = node;
1174
1163
  const handle = defineAnnotatedType();
1175
- handle.designType(prim.id === "never" ? "never" : prim.id === "phantom" ? "phantom" : prim.config.type);
1164
+ handle.designType(prim.id === "never" ? "never" : prim.config.type);
1176
1165
  if (!skipAnnotations) this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1177
1166
  return handle;
1178
1167
  }
@@ -1299,7 +1288,7 @@ else handle.prop(prop.id, propHandle.$type);
1299
1288
  return this;
1300
1289
  }
1301
1290
  definePrimitive(node, name) {
1302
- this.renderPrimitiveDef(node.id === "never" ? "never" : node.id === "phantom" ? "phantom" : node.config.type, name);
1291
+ this.renderPrimitiveDef(node.id === "never" ? "never" : node.config.type, name);
1303
1292
  this.writeln(` .tags(${Array.from(node.tags).map((f) => `"${escapeQuotes(f)}"`).join(", ")})`);
1304
1293
  return this;
1305
1294
  }
package/dist/index.cjs CHANGED
@@ -295,8 +295,9 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
295
295
  patterns.push(prop);
296
296
  continue;
297
297
  }
298
- if (this.isPhantomProp(prop.getDefinition())) {
299
- this.writeln(`// ${prop.id}: phantom`);
298
+ const phantomType = this.phantomPropType(prop.getDefinition());
299
+ if (phantomType) {
300
+ this.writeln(`// ${prop.id}: ${phantomType}`);
300
301
  continue;
301
302
  }
302
303
  const optional = !!prop.token("optional");
@@ -342,12 +343,6 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
342
343
  if (struct?.entity === "structure") this.renderStructure(struct, node.id);
343
344
  else this.writeln("{}");
344
345
  this.writeln();
345
- const nsPrefix = exported ? "export declare" : "declare";
346
- this.write(`${nsPrefix} namespace ${node.id} `);
347
- this.blockln("{}");
348
- this.writeln(`type DataType = ${node.id}`);
349
- this.popln();
350
- this.writeln();
351
346
  }
352
347
  renderType(node) {
353
348
  this.writeln();
@@ -374,12 +369,6 @@ else this.writeln("{}");
374
369
  } else {
375
370
  this.write(exported ? "export declare " : "declare ");
376
371
  this.writeln(`class ${node.id} extends ${targetName} {}`);
377
- const nsPrefix = exported ? "export declare" : "declare";
378
- this.write(`${nsPrefix} namespace ${node.id} `);
379
- this.blockln("{}");
380
- this.writeln(`type DataType = ${node.id}`);
381
- this.popln();
382
- this.writeln();
383
372
  }
384
373
  }
385
374
  renderTypeNamespace(node) {
@@ -398,23 +387,23 @@ else if ((0, __atscript_core.isGroup)(realDef)) typeDef = `TAtscriptTypeComplex<
398
387
  else if ((0, __atscript_core.isArray)(realDef)) typeDef = `TAtscriptTypeArray<${name}>`;
399
388
  else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
400
389
  }
401
- this.writeln(`type DataType = ${name}`);
402
390
  this.writeln(`const __is_atscript_annotated_type: true`);
403
391
  this.writeln(`const type: ${typeDef}`);
404
392
  this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
405
- this.writeln(`const validator: (opts?: Partial<TValidatorOptions>) => Validator<typeof ${name}, ${name}>`);
393
+ this.writeln(`const validator: (opts?: Partial<TValidatorOptions>) => Validator<typeof ${name}>`);
406
394
  if (resolveJsonSchemaMode(this.opts) === false) this.writeln("/** @deprecated JSON Schema support is disabled. Calling this method will throw a runtime error. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add `@emit.jsonSchema` annotation to individual interfaces. */");
407
395
  this.writeln("const toJsonSchema: () => any");
408
396
  this.popln();
409
397
  }
410
- isPhantomProp(def) {
411
- if (!def) return false;
412
- if ((0, __atscript_core.isPrimitive)(def) && def.id === "phantom") return true;
398
+ phantomPropType(def) {
399
+ if (!def) return undefined;
400
+ if ((0, __atscript_core.isPrimitive)(def) && def.config.type === "phantom") return def.id;
413
401
  if ((0, __atscript_core.isRef)(def)) {
414
- const unwound = this.doc.unwindType(def.id, def.chain)?.def;
415
- return (0, __atscript_core.isPrimitive)(unwound) && unwound.id === "phantom";
402
+ const ref = def;
403
+ const unwound = this.doc.unwindType(ref.id, ref.chain)?.def;
404
+ if ((0, __atscript_core.isPrimitive)(unwound) && unwound.config.type === "phantom") return ref.hasChain ? `${ref.id}.${ref.chain.map((c) => c.text).join(".")}` : ref.id;
416
405
  }
417
- return false;
406
+ return undefined;
418
407
  }
419
408
  isTypeTarget(name, doc) {
420
409
  const d = doc || this.doc;
@@ -1169,7 +1158,7 @@ else {
1169
1158
  case "primitive": {
1170
1159
  const prim = node;
1171
1160
  const handle = defineAnnotatedType();
1172
- handle.designType(prim.id === "never" ? "never" : prim.id === "phantom" ? "phantom" : prim.config.type);
1161
+ handle.designType(prim.id === "never" ? "never" : prim.config.type);
1173
1162
  if (!skipAnnotations) this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1174
1163
  return handle;
1175
1164
  }
@@ -1296,7 +1285,7 @@ else handle.prop(prop.id, propHandle.$type);
1296
1285
  return this;
1297
1286
  }
1298
1287
  definePrimitive(node, name) {
1299
- this.renderPrimitiveDef(node.id === "never" ? "never" : node.id === "phantom" ? "phantom" : node.config.type, name);
1288
+ this.renderPrimitiveDef(node.id === "never" ? "never" : node.config.type, name);
1300
1289
  this.writeln(` .tags(${Array.from(node.tags).map((f) => `"${escapeQuotes(f)}"`).join(", ")})`);
1301
1290
  return this;
1302
1291
  }
package/dist/index.mjs CHANGED
@@ -271,8 +271,9 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
271
271
  patterns.push(prop);
272
272
  continue;
273
273
  }
274
- if (this.isPhantomProp(prop.getDefinition())) {
275
- this.writeln(`// ${prop.id}: phantom`);
274
+ const phantomType = this.phantomPropType(prop.getDefinition());
275
+ if (phantomType) {
276
+ this.writeln(`// ${prop.id}: ${phantomType}`);
276
277
  continue;
277
278
  }
278
279
  const optional = !!prop.token("optional");
@@ -318,12 +319,6 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
318
319
  if (struct?.entity === "structure") this.renderStructure(struct, node.id);
319
320
  else this.writeln("{}");
320
321
  this.writeln();
321
- const nsPrefix = exported ? "export declare" : "declare";
322
- this.write(`${nsPrefix} namespace ${node.id} `);
323
- this.blockln("{}");
324
- this.writeln(`type DataType = ${node.id}`);
325
- this.popln();
326
- this.writeln();
327
322
  }
328
323
  renderType(node) {
329
324
  this.writeln();
@@ -350,12 +345,6 @@ else this.writeln("{}");
350
345
  } else {
351
346
  this.write(exported ? "export declare " : "declare ");
352
347
  this.writeln(`class ${node.id} extends ${targetName} {}`);
353
- const nsPrefix = exported ? "export declare" : "declare";
354
- this.write(`${nsPrefix} namespace ${node.id} `);
355
- this.blockln("{}");
356
- this.writeln(`type DataType = ${node.id}`);
357
- this.popln();
358
- this.writeln();
359
348
  }
360
349
  }
361
350
  renderTypeNamespace(node) {
@@ -374,23 +363,23 @@ else if (isGroup(realDef)) typeDef = `TAtscriptTypeComplex<${name}>`;
374
363
  else if (isArray(realDef)) typeDef = `TAtscriptTypeArray<${name}>`;
375
364
  else if (isPrimitive(realDef)) typeDef = `TAtscriptTypeFinal<${name}>`;
376
365
  }
377
- this.writeln(`type DataType = ${name}`);
378
366
  this.writeln(`const __is_atscript_annotated_type: true`);
379
367
  this.writeln(`const type: ${typeDef}`);
380
368
  this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
381
- this.writeln(`const validator: (opts?: Partial<TValidatorOptions>) => Validator<typeof ${name}, ${name}>`);
369
+ this.writeln(`const validator: (opts?: Partial<TValidatorOptions>) => Validator<typeof ${name}>`);
382
370
  if (resolveJsonSchemaMode(this.opts) === false) this.writeln("/** @deprecated JSON Schema support is disabled. Calling this method will throw a runtime error. To enable, set `jsonSchema: 'lazy'` or `jsonSchema: 'bundle'` in tsPlugin options, or add `@emit.jsonSchema` annotation to individual interfaces. */");
383
371
  this.writeln("const toJsonSchema: () => any");
384
372
  this.popln();
385
373
  }
386
- isPhantomProp(def) {
387
- if (!def) return false;
388
- if (isPrimitive(def) && def.id === "phantom") return true;
374
+ phantomPropType(def) {
375
+ if (!def) return undefined;
376
+ if (isPrimitive(def) && def.config.type === "phantom") return def.id;
389
377
  if (isRef(def)) {
390
- const unwound = this.doc.unwindType(def.id, def.chain)?.def;
391
- return isPrimitive(unwound) && unwound.id === "phantom";
378
+ const ref = def;
379
+ const unwound = this.doc.unwindType(ref.id, ref.chain)?.def;
380
+ if (isPrimitive(unwound) && unwound.config.type === "phantom") return ref.hasChain ? `${ref.id}.${ref.chain.map((c) => c.text).join(".")}` : ref.id;
392
381
  }
393
- return false;
382
+ return undefined;
394
383
  }
395
384
  isTypeTarget(name, doc) {
396
385
  const d = doc || this.doc;
@@ -1145,7 +1134,7 @@ else {
1145
1134
  case "primitive": {
1146
1135
  const prim = node;
1147
1136
  const handle = defineAnnotatedType();
1148
- handle.designType(prim.id === "never" ? "never" : prim.id === "phantom" ? "phantom" : prim.config.type);
1137
+ handle.designType(prim.id === "never" ? "never" : prim.config.type);
1149
1138
  if (!skipAnnotations) this.applyExpectAnnotations(handle, this.doc.evalAnnotationsForNode(node));
1150
1139
  return handle;
1151
1140
  }
@@ -1272,7 +1261,7 @@ else handle.prop(prop.id, propHandle.$type);
1272
1261
  return this;
1273
1262
  }
1274
1263
  definePrimitive(node, name) {
1275
- this.renderPrimitiveDef(node.id === "never" ? "never" : node.id === "phantom" ? "phantom" : node.config.type, name);
1264
+ this.renderPrimitiveDef(node.id === "never" ? "never" : node.config.type, name);
1276
1265
  this.writeln(` .tags(${Array.from(node.tags).map((f) => `"${escapeQuotes(f)}"`).join(", ")})`);
1277
1266
  return this;
1278
1267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/typescript",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Atscript: typescript-gen support.",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -70,7 +70,7 @@
70
70
  "homepage": "https://github.com/moostjs/atscript/tree/main/packages/typescript#readme",
71
71
  "license": "ISC",
72
72
  "peerDependencies": {
73
- "@atscript/core": "^0.1.4"
73
+ "@atscript/core": "^0.1.6"
74
74
  },
75
75
  "dependencies": {
76
76
  "@moostjs/event-cli": "^0.5.32",