@atscript/typescript 0.2.13 → 0.2.15

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
@@ -1,6 +1,6 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_plugin = require('./plugin-BNbjc9-d.cjs');
3
- const require_user_text = require('./user-text-BrP_qD3T.cjs');
2
+ const require_plugin = require('./plugin-C76__OEt.cjs');
3
+ const require_user_text = require('./user-text-nlqi2Pcp.cjs');
4
4
 
5
5
  exports.JS_COMPILED_FORMAT = require_plugin.JS_COMPILED_FORMAT;
6
6
  exports.JS_INTERPRETED_FORMAT = require_plugin.JS_INTERPRETED_FORMAT;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as withLoadCheck, i as importCycle, n as JS_INTERPRETED_FORMAT, r as tsPlugin, t as JS_COMPILED_FORMAT } from "./plugin-CnraKYN3.mjs";
2
- import { X as invalidateCompiledValidators } from "./user-text-DS0lorlV.mjs";
1
+ import { a as withLoadCheck, i as importCycle, n as JS_INTERPRETED_FORMAT, r as tsPlugin, t as JS_COMPILED_FORMAT } from "./plugin-DylX_2HB.mjs";
2
+ import { X as invalidateCompiledValidators } from "./user-text-ChmfJbNv.mjs";
3
3
 
4
4
  export { JS_COMPILED_FORMAT, JS_INTERPRETED_FORMAT, tsPlugin as default, tsPlugin, importCycle, invalidateCompiledValidators, withLoadCheck };
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
 
27
27
  //#endregion
28
- const require_user_text = require('./user-text-BrP_qD3T.cjs');
28
+ const require_user_text = require('./user-text-nlqi2Pcp.cjs');
29
29
  let path = require("path");
30
30
  path = __toESM(path);
31
31
  let _atscript_core = require("@atscript/core");
@@ -1,4 +1,4 @@
1
- import { n as CORE_USER_TEXT, o as uniqueName, v as stageEnds } from "./user-text-DS0lorlV.mjs";
1
+ import { n as CORE_USER_TEXT, o as uniqueName, v as stageEnds } from "./user-text-ChmfJbNv.mjs";
2
2
  import path from "path";
3
3
  import { ANNOTATE_RESET, DEFAULT_FORMAT, MERGE_TOO_COMPLEX, NAV_PROP_ANNOTATIONS, SemanticGroup, andExprs, annotatedValueKinds, componentOf, components, defPosition, documentsEpoch, entryParts, flatDefinitions, forEachAnnotationSpec, getRelPath, hasMutatingAnnotates, hasNavPropAnnotation, isAnnotate, isArray, isAsView, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isInterface, isNull, isPhantomNode, isPrimitive, isQueryLogical, isRef, isStructure, isTuple, moduleId, pastViews, resolveAtscriptFromPath, unshell, userTextFields, withoutAsExtension } from "@atscript/core";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -3166,10 +3166,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3166
3166
  const kept = this.strips.length;
3167
3167
  let details;
3168
3168
  /**
3169
- * Where each failed branch's errors start in `details` (by branch index): plain object
3170
- * values only, the ones a discriminator can report (see `discriminatedErrors`).
3169
+ * Where each failed branch's errors start in `details` (by branch index): object and array
3170
+ * values only, the ones a branch's errors can be reported for (see `discriminatedErrors`,
3171
+ * `nullableErrors`).
3171
3172
  */ let starts;
3172
- const plainObject = typeof value === "object" && value !== null && !Array.isArray(value);
3173
+ const objectValue = typeof value === "object" && value !== null;
3173
3174
  for (const item of items) {
3174
3175
  this.stackErrors.push(null);
3175
3176
  const failures = this.nestedFailures;
@@ -3186,11 +3187,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3186
3187
  if (this.limitExceeded) this.limitExceeded = false;
3187
3188
  if (this.nestedFailures !== failures) this.wasteBranch();
3188
3189
  if (nested) this.nestedFailures++;
3189
- if (plainObject) (starts ?? (starts = [])).push(details?.length ?? 0);
3190
+ if (objectValue) (starts ?? (starts = [])).push(details?.length ?? 0);
3190
3191
  if (branchErrors) if (details) for (const err of branchErrors) details.push(err);
3191
3192
  else details = branchErrors;
3192
3193
  }
3193
- const errors = this.discriminatedErrors(def, value, details, starts ?? []) ?? this.unionError(def, details);
3194
+ const errors = this.discriminatedErrors(def, value, details, starts ?? []) ?? this.nullableErrors(def, value, details, starts ?? []) ?? this.unionError(def, details);
3194
3195
  if (path !== void 0) this.decide(def, value, path, kept, void 0, errors);
3195
3196
  return false;
3196
3197
  }
@@ -3219,7 +3220,32 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3219
3220
  const at = this.depth > 0 ? `${this.buildPath()}.${disc.property}` : disc.property;
3220
3221
  return [this.builtin("UNION_DISCRIMINATOR", params, expectMessage(def), at)];
3221
3222
  }
3222
- const index = disc.branches[picked][0];
3223
+ return this.branchErrors(details, starts, disc.branches[picked][0]);
3224
+ }
3225
+ /**
3226
+ * The errors of a nullable union (`T | null`) over a `value` of `T`'s kind (a non-array object
3227
+ * for an object `T`, an array for an array or tuple `T`), reported in place of the union error:
3228
+ * the errors of `T`, the one branch that is not `null` (the `null` branch was never a
3229
+ * candidate). `undefined` (nothing reported) for other unions and values, and when `T` failed
3230
+ * without errors.
3231
+ */ nullableErrors(def, value, details, starts) {
3232
+ if (typeof value !== "object" || value === null) return;
3233
+ const items = def.type.items;
3234
+ let index = -1;
3235
+ for (let i = 0; i < items.length; i++) {
3236
+ const type = items[i].type;
3237
+ if (type.kind === "" && type.designType === "null") continue;
3238
+ if (index >= 0) return;
3239
+ index = i;
3240
+ }
3241
+ const kind = items[index]?.type.kind;
3242
+ if (Array.isArray(value) ? kind !== "array" && kind !== "tuple" : kind !== "object") return;
3243
+ return this.branchErrors(details, starts, index);
3244
+ }
3245
+ /**
3246
+ * Reports the errors of failed branch `index` (its slice of `details`, by `starts`) in place of
3247
+ * the union error; `undefined` (nothing reported) when it failed without errors.
3248
+ */ branchErrors(details, starts, index) {
3223
3249
  const errors = details?.slice(starts[index], starts[index + 1] ?? details.length);
3224
3250
  if (errors === void 0 || errors.length === 0) return;
3225
3251
  this.reportAll(errors);
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_plugin = require('./plugin-BNbjc9-d.cjs');
3
- const require_user_text = require('./user-text-BrP_qD3T.cjs');
2
+ const require_plugin = require('./plugin-C76__OEt.cjs');
3
+ const require_user_text = require('./user-text-nlqi2Pcp.cjs');
4
4
  let path = require("path");
5
5
  path = require_plugin.__toESM(path);
6
6
  let _atscript_core = require("@atscript/core");
@@ -317,6 +317,19 @@ declare class Validator<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedTyp
317
317
  * when it picks none. `undefined` (nothing reported) for other unions and values.
318
318
  */
319
319
  private discriminatedErrors;
320
+ /**
321
+ * The errors of a nullable union (`T | null`) over a `value` of `T`'s kind (a non-array object
322
+ * for an object `T`, an array for an array or tuple `T`), reported in place of the union error:
323
+ * the errors of `T`, the one branch that is not `null` (the `null` branch was never a
324
+ * candidate). `undefined` (nothing reported) for other unions and values, and when `T` failed
325
+ * without errors.
326
+ */
327
+ private nullableErrors;
328
+ /**
329
+ * Reports the errors of failed branch `index` (its slice of `details`, by `starts`) in place of
330
+ * the union error; `undefined` (nothing reported) when it failed without errors.
331
+ */
332
+ private branchErrors;
320
333
  /** Reports `errors`, made already, until the error limit is reached. */
321
334
  private reportAll;
322
335
  /** Whether missing props are allowed at the current depth (the `partial` option). */
@@ -1,5 +1,5 @@
1
- import { r as tsPlugin } from "./plugin-CnraKYN3.mjs";
2
- import { j as Validator } from "./user-text-DS0lorlV.mjs";
1
+ import { r as tsPlugin } from "./plugin-DylX_2HB.mjs";
2
+ import { j as Validator } from "./user-text-ChmfJbNv.mjs";
3
3
  import path from "path";
4
4
  import { build } from "@atscript/core";
5
5
  import { readFileSync, writeFileSync } from "fs";
@@ -2653,10 +2653,11 @@ function _define_property(obj, key, value) {
2653
2653
  const kept = this.strips.length;
2654
2654
  let details;
2655
2655
  /**
2656
- * Where each failed branch's errors start in `details` (by branch index): plain object
2657
- * values only, the ones a discriminator can report (see `discriminatedErrors`).
2656
+ * Where each failed branch's errors start in `details` (by branch index): object and array
2657
+ * values only, the ones a branch's errors can be reported for (see `discriminatedErrors`,
2658
+ * `nullableErrors`).
2658
2659
  */ let starts;
2659
- const plainObject = typeof value === "object" && value !== null && !Array.isArray(value);
2660
+ const objectValue = typeof value === "object" && value !== null;
2660
2661
  for (const item of items) {
2661
2662
  this.stackErrors.push(null);
2662
2663
  const failures = this.nestedFailures;
@@ -2673,11 +2674,11 @@ function _define_property(obj, key, value) {
2673
2674
  if (this.limitExceeded) this.limitExceeded = false;
2674
2675
  if (this.nestedFailures !== failures) this.wasteBranch();
2675
2676
  if (nested) this.nestedFailures++;
2676
- if (plainObject) (starts ?? (starts = [])).push(details?.length ?? 0);
2677
+ if (objectValue) (starts ?? (starts = [])).push(details?.length ?? 0);
2677
2678
  if (branchErrors) if (details) for (const err of branchErrors) details.push(err);
2678
2679
  else details = branchErrors;
2679
2680
  }
2680
- const errors = this.discriminatedErrors(def, value, details, starts ?? []) ?? this.unionError(def, details);
2681
+ const errors = this.discriminatedErrors(def, value, details, starts ?? []) ?? this.nullableErrors(def, value, details, starts ?? []) ?? this.unionError(def, details);
2681
2682
  if (path !== void 0) this.decide(def, value, path, kept, void 0, errors);
2682
2683
  return false;
2683
2684
  }
@@ -2706,7 +2707,32 @@ function _define_property(obj, key, value) {
2706
2707
  const at = this.depth > 0 ? `${this.buildPath()}.${disc.property}` : disc.property;
2707
2708
  return [this.builtin("UNION_DISCRIMINATOR", params, expectMessage(def), at)];
2708
2709
  }
2709
- const index = disc.branches[picked][0];
2710
+ return this.branchErrors(details, starts, disc.branches[picked][0]);
2711
+ }
2712
+ /**
2713
+ * The errors of a nullable union (`T | null`) over a `value` of `T`'s kind (a non-array object
2714
+ * for an object `T`, an array for an array or tuple `T`), reported in place of the union error:
2715
+ * the errors of `T`, the one branch that is not `null` (the `null` branch was never a
2716
+ * candidate). `undefined` (nothing reported) for other unions and values, and when `T` failed
2717
+ * without errors.
2718
+ */ nullableErrors(def, value, details, starts) {
2719
+ if (typeof value !== "object" || value === null) return;
2720
+ const items = def.type.items;
2721
+ let index = -1;
2722
+ for (let i = 0; i < items.length; i++) {
2723
+ const type = items[i].type;
2724
+ if (type.kind === "" && type.designType === "null") continue;
2725
+ if (index >= 0) return;
2726
+ index = i;
2727
+ }
2728
+ const kind = items[index]?.type.kind;
2729
+ if (Array.isArray(value) ? kind !== "array" && kind !== "tuple" : kind !== "object") return;
2730
+ return this.branchErrors(details, starts, index);
2731
+ }
2732
+ /**
2733
+ * Reports the errors of failed branch `index` (its slice of `details`, by `starts`) in place of
2734
+ * the union error; `undefined` (nothing reported) when it failed without errors.
2735
+ */ branchErrors(details, starts, index) {
2710
2736
  const errors = details?.slice(starts[index], starts[index + 1] ?? details.length);
2711
2737
  if (errors === void 0 || errors.length === 0) return;
2712
2738
  this.reportAll(errors);
@@ -2654,10 +2654,11 @@ function _define_property(obj, key, value) {
2654
2654
  const kept = this.strips.length;
2655
2655
  let details;
2656
2656
  /**
2657
- * Where each failed branch's errors start in `details` (by branch index): plain object
2658
- * values only, the ones a discriminator can report (see `discriminatedErrors`).
2657
+ * Where each failed branch's errors start in `details` (by branch index): object and array
2658
+ * values only, the ones a branch's errors can be reported for (see `discriminatedErrors`,
2659
+ * `nullableErrors`).
2659
2660
  */ let starts;
2660
- const plainObject = typeof value === "object" && value !== null && !Array.isArray(value);
2661
+ const objectValue = typeof value === "object" && value !== null;
2661
2662
  for (const item of items) {
2662
2663
  this.stackErrors.push(null);
2663
2664
  const failures = this.nestedFailures;
@@ -2674,11 +2675,11 @@ function _define_property(obj, key, value) {
2674
2675
  if (this.limitExceeded) this.limitExceeded = false;
2675
2676
  if (this.nestedFailures !== failures) this.wasteBranch();
2676
2677
  if (nested) this.nestedFailures++;
2677
- if (plainObject) (starts ?? (starts = [])).push(details?.length ?? 0);
2678
+ if (objectValue) (starts ?? (starts = [])).push(details?.length ?? 0);
2678
2679
  if (branchErrors) if (details) for (const err of branchErrors) details.push(err);
2679
2680
  else details = branchErrors;
2680
2681
  }
2681
- const errors = this.discriminatedErrors(def, value, details, starts ?? []) ?? this.unionError(def, details);
2682
+ const errors = this.discriminatedErrors(def, value, details, starts ?? []) ?? this.nullableErrors(def, value, details, starts ?? []) ?? this.unionError(def, details);
2682
2683
  if (path !== void 0) this.decide(def, value, path, kept, void 0, errors);
2683
2684
  return false;
2684
2685
  }
@@ -2707,7 +2708,32 @@ function _define_property(obj, key, value) {
2707
2708
  const at = this.depth > 0 ? `${this.buildPath()}.${disc.property}` : disc.property;
2708
2709
  return [this.builtin("UNION_DISCRIMINATOR", params, expectMessage(def), at)];
2709
2710
  }
2710
- const index = disc.branches[picked][0];
2711
+ return this.branchErrors(details, starts, disc.branches[picked][0]);
2712
+ }
2713
+ /**
2714
+ * The errors of a nullable union (`T | null`) over a `value` of `T`'s kind (a non-array object
2715
+ * for an object `T`, an array for an array or tuple `T`), reported in place of the union error:
2716
+ * the errors of `T`, the one branch that is not `null` (the `null` branch was never a
2717
+ * candidate). `undefined` (nothing reported) for other unions and values, and when `T` failed
2718
+ * without errors.
2719
+ */ nullableErrors(def, value, details, starts) {
2720
+ if (typeof value !== "object" || value === null) return;
2721
+ const items = def.type.items;
2722
+ let index = -1;
2723
+ for (let i = 0; i < items.length; i++) {
2724
+ const type = items[i].type;
2725
+ if (type.kind === "" && type.designType === "null") continue;
2726
+ if (index >= 0) return;
2727
+ index = i;
2728
+ }
2729
+ const kind = items[index]?.type.kind;
2730
+ if (Array.isArray(value) ? kind !== "array" && kind !== "tuple" : kind !== "object") return;
2731
+ return this.branchErrors(details, starts, index);
2732
+ }
2733
+ /**
2734
+ * Reports the errors of failed branch `index` (its slice of `details`, by `starts`) in place of
2735
+ * the union error; `undefined` (nothing reported) when it failed without errors.
2736
+ */ branchErrors(details, starts, index) {
2711
2737
  const errors = details?.slice(starts[index], starts[index + 1] ?? details.length);
2712
2738
  if (errors === void 0 || errors.length === 0) return;
2713
2739
  this.reportAll(errors);
package/dist/utils.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_user_text = require('./user-text-BrP_qD3T.cjs');
2
+ const require_user_text = require('./user-text-nlqi2Pcp.cjs');
3
3
 
4
4
  //#region packages/typescript/src/runtime/copy-on-change.ts
5
5
  /**
package/dist/utils.d.ts CHANGED
@@ -388,6 +388,19 @@ declare class Validator<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedTyp
388
388
  * when it picks none. `undefined` (nothing reported) for other unions and values.
389
389
  */
390
390
  private discriminatedErrors;
391
+ /**
392
+ * The errors of a nullable union (`T | null`) over a `value` of `T`'s kind (a non-array object
393
+ * for an object `T`, an array for an array or tuple `T`), reported in place of the union error:
394
+ * the errors of `T`, the one branch that is not `null` (the `null` branch was never a
395
+ * candidate). `undefined` (nothing reported) for other unions and values, and when `T` failed
396
+ * without errors.
397
+ */
398
+ private nullableErrors;
399
+ /**
400
+ * Reports the errors of failed branch `index` (its slice of `details`, by `starts`) in place of
401
+ * the union error; `undefined` (nothing reported) when it failed without errors.
402
+ */
403
+ private branchErrors;
391
404
  /** Reports `errors`, made already, until the error limit is reached. */
392
405
  private reportAll;
393
406
  /** Whether missing props are allowed at the current depth (the `partial` option). */
package/dist/utils.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as DECIMAL_RE, A as propAtChain, B as acceptsNull$2, C as createAnnotatedTypeNode, D as isAnnotatedType, E as defineAnnotatedType, F as VALIDATOR_MESSAGES, G as $ak, H as detectDiscriminator, I as formatCodeOf, J as metaEmpty, K as $nr, L as formatValidatorMessage, M as ValidatorError, N as unionDiscriminator, O as isAnnotatedTypeOfPrimitive, P as VALIDATOR_ERROR_CODES, Q as typeWriteCount, R as localizeErrors, S as annotate, T as createObjectTypeDef, U as jsonSchemaPattern, V as registerCompiledCheck, W as statelessRegExp, X as invalidateCompiledValidators, Y as watchLayer, Z as touched, _ as pendingStatements, a as userTextOf, b as cutKey, c as $blk, d as $fc, et as VALIDATOR_KEYS, f as $ft, g as appliedBlockModules, h as $sh, i as userTextKeys, j as Validator, k as isPhantomType, l as $end, m as $q, nt as boundOf, o as uniqueName, p as $ps, q as LayerMap, r as registerUserText, s as $alias, t as $ut, tt as arrayKeyProps, u as $f, w as createMetadataMap, x as enterCut, y as cutAs, z as messagesTranslator } from "./user-text-DS0lorlV.mjs";
1
+ import { $ as DECIMAL_RE, A as propAtChain, B as acceptsNull$2, C as createAnnotatedTypeNode, D as isAnnotatedType, E as defineAnnotatedType, F as VALIDATOR_MESSAGES, G as $ak, H as detectDiscriminator, I as formatCodeOf, J as metaEmpty, K as $nr, L as formatValidatorMessage, M as ValidatorError, N as unionDiscriminator, O as isAnnotatedTypeOfPrimitive, P as VALIDATOR_ERROR_CODES, Q as typeWriteCount, R as localizeErrors, S as annotate, T as createObjectTypeDef, U as jsonSchemaPattern, V as registerCompiledCheck, W as statelessRegExp, X as invalidateCompiledValidators, Y as watchLayer, Z as touched, _ as pendingStatements, a as userTextOf, b as cutKey, c as $blk, d as $fc, et as VALIDATOR_KEYS, f as $ft, g as appliedBlockModules, h as $sh, i as userTextKeys, j as Validator, k as isPhantomType, l as $end, m as $q, nt as boundOf, o as uniqueName, p as $ps, q as LayerMap, r as registerUserText, s as $alias, t as $ut, tt as arrayKeyProps, u as $f, w as createMetadataMap, x as enterCut, y as cutAs, z as messagesTranslator } from "./user-text-ChmfJbNv.mjs";
2
2
 
3
3
  //#region packages/typescript/src/runtime/copy-on-change.ts
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/typescript",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "Atscript: typescript-gen support.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -63,18 +63,18 @@
63
63
  "./package.json": "./package.json"
64
64
  },
65
65
  "dependencies": {
66
- "@moostjs/event-cli": "^0.7.6",
67
- "moost": "^0.7.6"
66
+ "@moostjs/event-cli": "^0.7.7",
67
+ "moost": "^0.7.7"
68
68
  },
69
69
  "devDependencies": {
70
- "@atscript/db": "^0.1.181",
70
+ "@atscript/db": "^0.1.186",
71
71
  "@uniqu/core": "^0.2.2",
72
72
  "ajv": "8.20.0",
73
73
  "vitest": "4.1.12"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "@atscript/db": "^0.1.159",
77
- "@atscript/core": "^0.2.13"
77
+ "@atscript/core": "^0.2.15"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@atscript/db": {