@atscript/typescript 0.0.28 → 0.0.29

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
@@ -154,7 +154,7 @@ var BaseRenderer = class extends CodePrinter {
154
154
  renderInterface(node) {}
155
155
  renderType(node) {}
156
156
  transformFromPath(path$3) {
157
- return path$3 + ".as";
157
+ return `${path$3}.as`;
158
158
  }
159
159
  renderImport(node) {
160
160
  const def = node.getDefinition();
@@ -219,7 +219,7 @@ function _define_property$3(obj, key, value) {
219
219
  else obj[key] = value;
220
220
  return obj;
221
221
  }
222
- var TypeRenderer = class extends BaseRenderer {
222
+ var TypeRenderer = class TypeRenderer extends BaseRenderer {
223
223
  pre() {
224
224
  this.writeln("// prettier-ignore-start");
225
225
  this.writeln("/* eslint-disable */");
@@ -234,6 +234,11 @@ var TypeRenderer = class extends BaseRenderer {
234
234
  post() {
235
235
  this.writeln("// prettier-ignore-end");
236
236
  }
237
+ renderTypeDefString(def) {
238
+ const newThis = new TypeRenderer(this.doc, this.opts);
239
+ newThis.renderTypeDef(def);
240
+ return newThis.toString();
241
+ }
237
242
  renderTypeDef(def) {
238
243
  if (!def) {
239
244
  this.write("unknown");
@@ -282,33 +287,33 @@ var TypeRenderer = class extends BaseRenderer {
282
287
  renderStructure(struct, asClass) {
283
288
  this.blockln("{}");
284
289
  const patterns = [];
285
- let hasProp = false;
290
+ const propsDefs = new Set();
286
291
  for (const prop of Array.from(struct.props.values())) {
287
292
  if (prop.token("identifier")?.pattern) {
288
293
  patterns.push(prop);
289
294
  continue;
290
295
  }
291
- hasProp = true;
292
296
  const optional = !!prop.token("optional");
293
297
  this.write(wrapProp(prop.id), optional ? "?" : "", ": ");
294
- this.renderTypeDef(prop.getDefinition());
295
- this.writeln();
298
+ const renderedDef = this.renderTypeDefString(prop.getDefinition());
299
+ propsDefs.add(renderedDef);
300
+ renderedDef.split("\n").forEach((l) => this.writeln(l));
296
301
  }
297
302
  if (patterns.length) {
298
303
  this.write(`[key: string]: `);
299
- if (hasProp) this.writeln("any");
300
- else if (patterns.length === 1) {
301
- this.renderTypeDef(patterns[0].getDefinition());
302
- this.writeln();
303
- } else {
304
- this.indent();
305
- for (const prop of patterns) {
304
+ if (patterns.length > 0) {
305
+ for (const prop of patterns) propsDefs.add(this.renderTypeDefString(prop.getDefinition()));
306
+ const defs = Array.from(propsDefs);
307
+ if (defs.length > 1) {
308
+ this.indent();
309
+ for (const def of defs) {
310
+ this.writeln();
311
+ this.write("| ");
312
+ def.split("\n").forEach((l) => this.write(l.trim()));
313
+ }
314
+ this.unindent();
306
315
  this.writeln();
307
- this.write("| ");
308
- this.renderTypeDef(prop.getDefinition());
309
- }
310
- this.unindent();
311
- this.writeln();
316
+ } else defs[0].split("\n").forEach((l) => this.writeln(l));
312
317
  }
313
318
  }
314
319
  if (asClass) {
@@ -359,7 +364,7 @@ else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = "TAtscriptTypeFina
359
364
  this.writeln(`const type: ${typeDef}`);
360
365
  this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
361
366
  this.writeln(`const validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${node.id}>(opts?: Partial<TValidatorOptions>) => Validator<TT>`);
362
- if (this.opts?.jsonSchema) this.writeln("const toJsonSchema: () => any");
367
+ this.writeln("const toJsonSchema: () => any");
363
368
  this.popln();
364
369
  }
365
370
  renderJsDoc(node) {
package/dist/index.cjs CHANGED
@@ -152,7 +152,7 @@ var BaseRenderer = class extends CodePrinter {
152
152
  renderInterface(node) {}
153
153
  renderType(node) {}
154
154
  transformFromPath(path$2) {
155
- return path$2 + ".as";
155
+ return `${path$2}.as`;
156
156
  }
157
157
  renderImport(node) {
158
158
  const def = node.getDefinition();
@@ -217,7 +217,7 @@ function _define_property$2(obj, key, value) {
217
217
  else obj[key] = value;
218
218
  return obj;
219
219
  }
220
- var TypeRenderer = class extends BaseRenderer {
220
+ var TypeRenderer = class TypeRenderer extends BaseRenderer {
221
221
  pre() {
222
222
  this.writeln("// prettier-ignore-start");
223
223
  this.writeln("/* eslint-disable */");
@@ -232,6 +232,11 @@ var TypeRenderer = class extends BaseRenderer {
232
232
  post() {
233
233
  this.writeln("// prettier-ignore-end");
234
234
  }
235
+ renderTypeDefString(def) {
236
+ const newThis = new TypeRenderer(this.doc, this.opts);
237
+ newThis.renderTypeDef(def);
238
+ return newThis.toString();
239
+ }
235
240
  renderTypeDef(def) {
236
241
  if (!def) {
237
242
  this.write("unknown");
@@ -280,33 +285,33 @@ var TypeRenderer = class extends BaseRenderer {
280
285
  renderStructure(struct, asClass) {
281
286
  this.blockln("{}");
282
287
  const patterns = [];
283
- let hasProp = false;
288
+ const propsDefs = new Set();
284
289
  for (const prop of Array.from(struct.props.values())) {
285
290
  if (prop.token("identifier")?.pattern) {
286
291
  patterns.push(prop);
287
292
  continue;
288
293
  }
289
- hasProp = true;
290
294
  const optional = !!prop.token("optional");
291
295
  this.write(wrapProp(prop.id), optional ? "?" : "", ": ");
292
- this.renderTypeDef(prop.getDefinition());
293
- this.writeln();
296
+ const renderedDef = this.renderTypeDefString(prop.getDefinition());
297
+ propsDefs.add(renderedDef);
298
+ renderedDef.split("\n").forEach((l) => this.writeln(l));
294
299
  }
295
300
  if (patterns.length) {
296
301
  this.write(`[key: string]: `);
297
- if (hasProp) this.writeln("any");
298
- else if (patterns.length === 1) {
299
- this.renderTypeDef(patterns[0].getDefinition());
300
- this.writeln();
301
- } else {
302
- this.indent();
303
- for (const prop of patterns) {
302
+ if (patterns.length > 0) {
303
+ for (const prop of patterns) propsDefs.add(this.renderTypeDefString(prop.getDefinition()));
304
+ const defs = Array.from(propsDefs);
305
+ if (defs.length > 1) {
306
+ this.indent();
307
+ for (const def of defs) {
308
+ this.writeln();
309
+ this.write("| ");
310
+ def.split("\n").forEach((l) => this.write(l.trim()));
311
+ }
312
+ this.unindent();
304
313
  this.writeln();
305
- this.write("| ");
306
- this.renderTypeDef(prop.getDefinition());
307
- }
308
- this.unindent();
309
- this.writeln();
314
+ } else defs[0].split("\n").forEach((l) => this.writeln(l));
310
315
  }
311
316
  }
312
317
  if (asClass) {
@@ -357,7 +362,7 @@ else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = "TAtscriptTypeFina
357
362
  this.writeln(`const type: ${typeDef}`);
358
363
  this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
359
364
  this.writeln(`const validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${node.id}>(opts?: Partial<TValidatorOptions>) => Validator<TT>`);
360
- if (this.opts?.jsonSchema) this.writeln("const toJsonSchema: () => any");
365
+ this.writeln("const toJsonSchema: () => any");
361
366
  this.popln();
362
367
  }
363
368
  renderJsDoc(node) {
package/dist/index.mjs CHANGED
@@ -127,7 +127,7 @@ var BaseRenderer = class extends CodePrinter {
127
127
  renderInterface(node) {}
128
128
  renderType(node) {}
129
129
  transformFromPath(path$1) {
130
- return path$1 + ".as";
130
+ return `${path$1}.as`;
131
131
  }
132
132
  renderImport(node) {
133
133
  const def = node.getDefinition();
@@ -192,7 +192,7 @@ function _define_property$2(obj, key, value) {
192
192
  else obj[key] = value;
193
193
  return obj;
194
194
  }
195
- var TypeRenderer = class extends BaseRenderer {
195
+ var TypeRenderer = class TypeRenderer extends BaseRenderer {
196
196
  pre() {
197
197
  this.writeln("// prettier-ignore-start");
198
198
  this.writeln("/* eslint-disable */");
@@ -207,6 +207,11 @@ var TypeRenderer = class extends BaseRenderer {
207
207
  post() {
208
208
  this.writeln("// prettier-ignore-end");
209
209
  }
210
+ renderTypeDefString(def) {
211
+ const newThis = new TypeRenderer(this.doc, this.opts);
212
+ newThis.renderTypeDef(def);
213
+ return newThis.toString();
214
+ }
210
215
  renderTypeDef(def) {
211
216
  if (!def) {
212
217
  this.write("unknown");
@@ -255,33 +260,33 @@ var TypeRenderer = class extends BaseRenderer {
255
260
  renderStructure(struct, asClass) {
256
261
  this.blockln("{}");
257
262
  const patterns = [];
258
- let hasProp = false;
263
+ const propsDefs = new Set();
259
264
  for (const prop of Array.from(struct.props.values())) {
260
265
  if (prop.token("identifier")?.pattern) {
261
266
  patterns.push(prop);
262
267
  continue;
263
268
  }
264
- hasProp = true;
265
269
  const optional = !!prop.token("optional");
266
270
  this.write(wrapProp(prop.id), optional ? "?" : "", ": ");
267
- this.renderTypeDef(prop.getDefinition());
268
- this.writeln();
271
+ const renderedDef = this.renderTypeDefString(prop.getDefinition());
272
+ propsDefs.add(renderedDef);
273
+ renderedDef.split("\n").forEach((l) => this.writeln(l));
269
274
  }
270
275
  if (patterns.length) {
271
276
  this.write(`[key: string]: `);
272
- if (hasProp) this.writeln("any");
273
- else if (patterns.length === 1) {
274
- this.renderTypeDef(patterns[0].getDefinition());
275
- this.writeln();
276
- } else {
277
- this.indent();
278
- for (const prop of patterns) {
277
+ if (patterns.length > 0) {
278
+ for (const prop of patterns) propsDefs.add(this.renderTypeDefString(prop.getDefinition()));
279
+ const defs = Array.from(propsDefs);
280
+ if (defs.length > 1) {
281
+ this.indent();
282
+ for (const def of defs) {
283
+ this.writeln();
284
+ this.write("| ");
285
+ def.split("\n").forEach((l) => this.write(l.trim()));
286
+ }
287
+ this.unindent();
279
288
  this.writeln();
280
- this.write("| ");
281
- this.renderTypeDef(prop.getDefinition());
282
- }
283
- this.unindent();
284
- this.writeln();
289
+ } else defs[0].split("\n").forEach((l) => this.writeln(l));
285
290
  }
286
291
  }
287
292
  if (asClass) {
@@ -332,7 +337,7 @@ else if (isPrimitive(realDef)) typeDef = "TAtscriptTypeFinal";
332
337
  this.writeln(`const type: ${typeDef}`);
333
338
  this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
334
339
  this.writeln(`const validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${node.id}>(opts?: Partial<TValidatorOptions>) => Validator<TT>`);
335
- if (this.opts?.jsonSchema) this.writeln("const toJsonSchema: () => any");
340
+ this.writeln("const toJsonSchema: () => any");
336
341
  this.popln();
337
342
  }
338
343
  renderJsDoc(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/typescript",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Atscript: typescript-gen support.",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -47,7 +47,7 @@
47
47
  "homepage": "https://github.com/moostjs/atscript/tree/main/packages/typescript#readme",
48
48
  "license": "ISC",
49
49
  "peerDependencies": {
50
- "@atscript/core": "^0.0.28"
50
+ "@atscript/core": "^0.0.29"
51
51
  },
52
52
  "dependencies": {
53
53
  "@moostjs/event-cli": "^0.5.32",