@atscript/typescript 0.2.6 → 0.2.8

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
@@ -4725,6 +4725,7 @@ const BANNER = DYE_COLORS.cyan(`
4725
4725
  #####
4726
4726
 
4727
4727
  `);
4728
+ const PENDING_HEADING = "Schema synced — work skipped in safe mode is still pending; the schema hash was not stored.";
4728
4729
  const PLAN_HEADER = [
4729
4730
  "",
4730
4731
  DYE_COLORS.bold("╔══════════════════════════════════════╗"),
@@ -4740,6 +4741,20 @@ const PLAN_HEADER = [
4740
4741
  refused: plan.entries.some((e) => e.refused)
4741
4742
  };
4742
4743
  }
4744
+ /** Run-level aggregates over the per-entry SyncEntry getters. */ function resultFlags(result) {
4745
+ return {
4746
+ errored: result.entries.filter((e) => e.hasErrors).length,
4747
+ hashWithheld: result.entries.some((e) => e.pending)
4748
+ };
4749
+ }
4750
+ /**
4751
+ * `Schema sync failed for N entries`, optionally pointing `see above`, and — only when a
4752
+ * pending entry withheld it — that the schema hash was not stored.
4753
+ */ function failedMessage(result, seeAbove = false) {
4754
+ const { errored, hashWithheld } = resultFlags(result);
4755
+ const notes = [seeAbove && "see above", hashWithheld && "the schema hash was not stored"].filter(Boolean).join("; ");
4756
+ return `Schema sync failed for ${`${errored} ${errored === 1 ? "entry" : "entries"}`}${notes && ` — ${notes}`}.`;
4757
+ }
4743
4758
  var DbSyncPrinter = class {
4744
4759
  log(...args) {
4745
4760
  if (!this.muted) console.log(...args);
@@ -4760,9 +4775,13 @@ var DbSyncPrinter = class {
4760
4775
  this.printGrouped(plan.entries, "plan");
4761
4776
  this.log("");
4762
4777
  }
4763
- result(result) {
4778
+ /** An applied run: every entry, under a failed, safe-mode pending or success heading. */ result(result) {
4779
+ const { errored, hashWithheld } = resultFlags(result);
4780
+ const c = this.colors;
4764
4781
  this.log("");
4765
- this.log(`${this.colors.green(this.colors.bold("Schema synced successfully."))} Hash: ${result.schemaHash}`);
4782
+ if (errored > 0) this.log(c.red(c.bold(failedMessage(result))));
4783
+ else if (hashWithheld) this.log(c.yellow(c.bold(PENDING_HEADING)));
4784
+ else this.log(`${c.green(c.bold("Schema synced successfully."))} Hash: ${result.schemaHash}`);
4766
4785
  this.log("");
4767
4786
  this.printGrouped(result.entries, "result");
4768
4787
  this.log("");
@@ -4935,13 +4954,14 @@ var DbSyncController = class {
4935
4954
  }
4936
4955
  }
4937
4956
  } else this.logger.log(`No destructive changes, proceeding to sync...`);
4938
- const result = await this.runSync(sync, dbTypes, safe);
4939
- this.printer.result(result);
4957
+ this.printer.result(await this.runSync(sync, dbTypes, safe));
4940
4958
  }
4941
4959
  /**
4942
- * Applies the sync. A refused run (`status: 'refused'`) issued no DDL and
4943
- * left tracking untouched — its refusal entries are printed and the command
4944
- * exits 1 instead of reporting a successful sync.
4960
+ * Applies the sync and returns a successful result. A refused run (`status: 'refused'`)
4961
+ * issued no DDL and left tracking untouched — its refusal entries are printed and the
4962
+ * command exits 1. An applied run that left entries with errors (`status: 'failed'` since
4963
+ * @atscript/db 0.1.170; earlier versions report `'synced'`, hence the entry check) is
4964
+ * printed and the command exits 1.
4945
4965
  */ async runSync(sync, dbTypes, safe) {
4946
4966
  const result = await sync.run(dbTypes, {
4947
4967
  force: true,
@@ -4951,6 +4971,10 @@ var DbSyncController = class {
4951
4971
  this.printer.refused(result);
4952
4972
  this.fail("Schema sync refused — nothing was applied. Fix the issues above and re-run.");
4953
4973
  }
4974
+ if (resultFlags(result).errored > 0) {
4975
+ this.printer.result(result);
4976
+ this.fail(failedMessage(result, true));
4977
+ }
4954
4978
  return result;
4955
4979
  }
4956
4980
  /**
@@ -4087,7 +4087,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4087
4087
  const UPPERCASE = 4;
4088
4088
  /**
4089
4089
  * Whether each node's subtree has normalizers: valid until the next type tree write (metadata or
4090
- * shape) or `invalidateCompiledValidators()` (checked by {@link normalizeForType}).
4090
+ * shape) or `invalidateCompiledValidators()` (checked by {@link typeHasNormalizers}).
4091
4091
  */ let reach = /* @__PURE__ */ new WeakMap();
4092
4092
  let stampWrites = -1;
4093
4093
  function newJudges(opts) {
@@ -4159,12 +4159,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4159
4159
  * normalizeForType(Patch, body, { partial: true })
4160
4160
  * ```
4161
4161
  */ function normalizeForType(def, value, opts) {
4162
- const writes = typeWriteCount();
4163
- if (writes !== stampWrites) {
4164
- stampWrites = writes;
4165
- reach = /* @__PURE__ */ new WeakMap();
4166
- }
4167
- if (!hasNormalizers(def)) return value;
4162
+ if (!typeHasNormalizers(def)) return value;
4168
4163
  const result = normalize(def, value, 0, {
4169
4164
  memo: /* @__PURE__ */ new Map(),
4170
4165
  root: value,
@@ -4189,6 +4184,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4189
4184
  }
4190
4185
  }
4191
4186
  /**
4187
+ * Whether {@link normalizeForType} can change a value of type `def`: `def` or a type its walk
4188
+ * reaches (props, pattern props, items, union and intersection members) carries `@normalize.*`.
4189
+ * Cached per type and kept current across type writes, so callers can skip their own walks.
4190
+ */ function typeHasNormalizers(def) {
4191
+ const writes = typeWriteCount();
4192
+ if (writes !== stampWrites) {
4193
+ stampWrites = writes;
4194
+ reach = /* @__PURE__ */ new WeakMap();
4195
+ }
4196
+ return hasNormalizers(def);
4197
+ }
4198
+ /**
4192
4199
  * Whether `def` or a node its walk reaches has normalizers. Answers (and caches) every node
4193
4200
  * reached, recursive types included: collects the reached nodes with their parents, then marks
4194
4201
  * the nodes with normalizers and, back along the parents, every node that reaches one.
@@ -7726,6 +7733,7 @@ exports.registerUserText = registerUserText;
7726
7733
  exports.serializeAnnotatedType = serializeAnnotatedType;
7727
7734
  exports.throwFeatureDisabled = throwFeatureDisabled;
7728
7735
  exports.translateServed = translateServed;
7736
+ exports.typeHasNormalizers = typeHasNormalizers;
7729
7737
  exports.unionDiscriminator = unionDiscriminator;
7730
7738
  exports.userTextKeys = userTextKeys;
7731
7739
  exports.userTextOf = userTextOf;
package/dist/utils.cjs CHANGED
@@ -92,7 +92,7 @@ const LOWERCASE = 2;
92
92
  const UPPERCASE = 4;
93
93
  /**
94
94
  * Whether each node's subtree has normalizers: valid until the next type tree write (metadata or
95
- * shape) or `invalidateCompiledValidators()` (checked by {@link normalizeForType}).
95
+ * shape) or `invalidateCompiledValidators()` (checked by {@link typeHasNormalizers}).
96
96
  */ let reach = /* @__PURE__ */ new WeakMap();
97
97
  let stampWrites = -1;
98
98
  function newJudges(opts) {
@@ -164,12 +164,7 @@ function judgesFor(opts) {
164
164
  * normalizeForType(Patch, body, { partial: true })
165
165
  * ```
166
166
  */ function normalizeForType(def, value, opts) {
167
- const writes = require_user_text.typeWriteCount();
168
- if (writes !== stampWrites) {
169
- stampWrites = writes;
170
- reach = /* @__PURE__ */ new WeakMap();
171
- }
172
- if (!hasNormalizers(def)) return value;
167
+ if (!typeHasNormalizers(def)) return value;
173
168
  const result = normalize(def, value, 0, {
174
169
  memo: /* @__PURE__ */ new Map(),
175
170
  root: value,
@@ -194,6 +189,18 @@ function judgesFor(opts) {
194
189
  }
195
190
  }
196
191
  /**
192
+ * Whether {@link normalizeForType} can change a value of type `def`: `def` or a type its walk
193
+ * reaches (props, pattern props, items, union and intersection members) carries `@normalize.*`.
194
+ * Cached per type and kept current across type writes, so callers can skip their own walks.
195
+ */ function typeHasNormalizers(def) {
196
+ const writes = require_user_text.typeWriteCount();
197
+ if (writes !== stampWrites) {
198
+ stampWrites = writes;
199
+ reach = /* @__PURE__ */ new WeakMap();
200
+ }
201
+ return hasNormalizers(def);
202
+ }
203
+ /**
197
204
  * Whether `def` or a node its walk reaches has normalizers. Answers (and caches) every node
198
205
  * reached, recursive types included: collects the reached nodes with their parents, then marks
199
206
  * the nodes with normalizers and, back along the parents, every node that reaches one.
@@ -2726,6 +2733,7 @@ exports.registerUserText = require_user_text.registerUserText;
2726
2733
  exports.serializeAnnotatedType = serializeAnnotatedType;
2727
2734
  exports.throwFeatureDisabled = throwFeatureDisabled;
2728
2735
  exports.translateServed = translateServed;
2736
+ exports.typeHasNormalizers = typeHasNormalizers;
2729
2737
  exports.unionDiscriminator = require_user_text.unionDiscriminator;
2730
2738
  exports.userTextKeys = require_user_text.userTextKeys;
2731
2739
  exports.userTextOf = require_user_text.userTextOf;
package/dist/utils.d.ts CHANGED
@@ -734,6 +734,12 @@ declare function coerceScalar(designType: TAtscriptTypeFinal['designType'], valu
734
734
  * ```
735
735
  */
736
736
  declare function normalizeForType<T = unknown>(def: TAtscriptAnnotatedType, value: T, opts?: Partial<TValidatorOptions>): T;
737
+ /**
738
+ * Whether {@link normalizeForType} can change a value of type `def`: `def` or a type its walk
739
+ * reaches (props, pattern props, items, union and intersection members) carries `@normalize.*`.
740
+ * Cached per type and kept current across type writes, so callers can skip their own walks.
741
+ */
742
+ declare function typeHasNormalizers(def: TAtscriptAnnotatedType): boolean;
737
743
 
738
744
  /** A JSON Schema object (draft-compatible). */
739
745
  type TJsonSchema = Record<string, any>;
@@ -1539,5 +1545,5 @@ type NavPropsOf<T> = T extends {
1539
1545
  __navProps: infer N extends Record<string, unknown>;
1540
1546
  } ? N : Record<string, never>;
1541
1547
 
1542
- export { $ak, $alias, $blk, $end, $f, $fc, $ft, $nr, $ps, $q, $sh, $ut, LayerMap, SERIALIZE_VERSION, VALIDATOR_ERROR_CODES, VALIDATOR_MESSAGES, Validator, ValidatorError, annotate, appliedBlockModules, buildJsonSchema, bundledSchemaOf, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, formatValidatorMessage, fromJsonSchema, invalidateCompiledValidators, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, lazyJsonSchema, localizeErrors, mergeJsonSchemas, messagesTranslator, metaEmpty, normalizeForType, pendingStatements, registerCompiledCheck, registerUserText, serializeAnnotatedType, throwFeatureDisabled, translateServed, unionDiscriminator, userTextKeys, userTextOf, watchLayer };
1548
+ export { $ak, $alias, $blk, $end, $f, $fc, $ft, $nr, $ps, $q, $sh, $ut, LayerMap, SERIALIZE_VERSION, VALIDATOR_ERROR_CODES, VALIDATOR_MESSAGES, Validator, ValidatorError, annotate, appliedBlockModules, buildJsonSchema, bundledSchemaOf, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, formatValidatorMessage, fromJsonSchema, invalidateCompiledValidators, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, lazyJsonSchema, localizeErrors, mergeJsonSchemas, messagesTranslator, metaEmpty, normalizeForType, pendingStatements, registerCompiledCheck, registerUserText, serializeAnnotatedType, throwFeatureDisabled, translateServed, typeHasNormalizers, unionDiscriminator, userTextKeys, userTextOf, watchLayer };
1543
1549
  export type { AtscriptExprNode, AtscriptOrderItem, AtscriptQueryComparison, AtscriptQueryFieldRef, AtscriptQueryNode, AtscriptRef, FlatOf, InferDataType, NavPropsOf, OwnPropsOf, PrimaryKeyOf, TAnnotatedTypeHandle, TAtscriptAnnotatedType, TAtscriptAnnotatedTypeConstructor, TAtscriptDataType, TAtscriptField, TAtscriptTypeArray, TAtscriptTypeComplex, TAtscriptTypeDef, TAtscriptTypeFinal, TAtscriptTypeObject, TCreateDataOptions, TError, TErrorInfo, TFlattenOptions, TJsonSchema, TJsonSchemaOptions, TMetadataMap, TProcessAnnotationContext, TSerializeOptions, TSerializedAnnotatedType, TSerializedAnnotatedTypeInner, TSerializedTypeArray, TSerializedTypeComplex, TSerializedTypeDef, TSerializedTypeFinal, TSerializedTypeObject, TUnionDiscriminator, TUserTextFields, TValidatorDiscriminator, TValidatorErrorCode, TValidatorOptions, TValidatorPlugin, TValidatorPluginContext, TValidatorTranslate, TValueResolver };
package/dist/utils.mjs CHANGED
@@ -91,7 +91,7 @@ const LOWERCASE = 2;
91
91
  const UPPERCASE = 4;
92
92
  /**
93
93
  * Whether each node's subtree has normalizers: valid until the next type tree write (metadata or
94
- * shape) or `invalidateCompiledValidators()` (checked by {@link normalizeForType}).
94
+ * shape) or `invalidateCompiledValidators()` (checked by {@link typeHasNormalizers}).
95
95
  */ let reach = /* @__PURE__ */ new WeakMap();
96
96
  let stampWrites = -1;
97
97
  function newJudges(opts) {
@@ -163,12 +163,7 @@ function judgesFor(opts) {
163
163
  * normalizeForType(Patch, body, { partial: true })
164
164
  * ```
165
165
  */ function normalizeForType(def, value, opts) {
166
- const writes = typeWriteCount();
167
- if (writes !== stampWrites) {
168
- stampWrites = writes;
169
- reach = /* @__PURE__ */ new WeakMap();
170
- }
171
- if (!hasNormalizers(def)) return value;
166
+ if (!typeHasNormalizers(def)) return value;
172
167
  const result = normalize(def, value, 0, {
173
168
  memo: /* @__PURE__ */ new Map(),
174
169
  root: value,
@@ -193,6 +188,18 @@ function judgesFor(opts) {
193
188
  }
194
189
  }
195
190
  /**
191
+ * Whether {@link normalizeForType} can change a value of type `def`: `def` or a type its walk
192
+ * reaches (props, pattern props, items, union and intersection members) carries `@normalize.*`.
193
+ * Cached per type and kept current across type writes, so callers can skip their own walks.
194
+ */ function typeHasNormalizers(def) {
195
+ const writes = typeWriteCount();
196
+ if (writes !== stampWrites) {
197
+ stampWrites = writes;
198
+ reach = /* @__PURE__ */ new WeakMap();
199
+ }
200
+ return hasNormalizers(def);
201
+ }
202
+ /**
196
203
  * Whether `def` or a node its walk reaches has normalizers. Answers (and caches) every node
197
204
  * reached, recursive types included: collects the reached nodes with their parents, then marks
198
205
  * the nodes with normalizers and, back along the parents, every node that reaches one.
@@ -2676,4 +2683,4 @@ let LiteralScanner = class LiteralScanner {
2676
2683
  }
2677
2684
 
2678
2685
  //#endregion
2679
- export { $ak, $alias, $blk, $end, $f, $fc, $ft, $nr, $ps, $q, $sh, $ut, LayerMap, SERIALIZE_VERSION, VALIDATOR_ERROR_CODES, VALIDATOR_MESSAGES, Validator, ValidatorError, annotate, appliedBlockModules, buildJsonSchema, bundledSchemaOf, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, formatValidatorMessage, fromJsonSchema, invalidateCompiledValidators, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, lazyJsonSchema, localizeErrors, mergeJsonSchemas, messagesTranslator, metaEmpty, normalizeForType, pendingStatements, registerCompiledCheck, registerUserText, serializeAnnotatedType, throwFeatureDisabled, translateServed, unionDiscriminator, userTextKeys, userTextOf, watchLayer };
2686
+ export { $ak, $alias, $blk, $end, $f, $fc, $ft, $nr, $ps, $q, $sh, $ut, LayerMap, SERIALIZE_VERSION, VALIDATOR_ERROR_CODES, VALIDATOR_MESSAGES, Validator, ValidatorError, annotate, appliedBlockModules, buildJsonSchema, bundledSchemaOf, coerceForType, coerceScalar, createAnnotatedTypeNode, createDataFromAnnotatedType, defineAnnotatedType, deserializeAnnotatedType, detectDiscriminator, flattenAnnotatedType, forAnnotatedType, formatValidatorMessage, fromJsonSchema, invalidateCompiledValidators, isAnnotatedType, isAnnotatedTypeOfPrimitive, isPhantomType, lazyJsonSchema, localizeErrors, mergeJsonSchemas, messagesTranslator, metaEmpty, normalizeForType, pendingStatements, registerCompiledCheck, registerUserText, serializeAnnotatedType, throwFeatureDisabled, translateServed, typeHasNormalizers, unionDiscriminator, userTextKeys, userTextOf, watchLayer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/typescript",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Atscript: typescript-gen support.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -67,14 +67,14 @@
67
67
  "moost": "^0.7.3"
68
68
  },
69
69
  "devDependencies": {
70
- "@atscript/db": "^0.1.167",
71
- "@uniqu/core": "^0.1.15",
70
+ "@atscript/db": "^0.1.170",
71
+ "@uniqu/core": "^0.2.1",
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.6"
77
+ "@atscript/core": "^0.2.8"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@atscript/db": {