@atscript/typescript 0.2.6 → 0.2.7

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
@@ -4920,7 +4920,13 @@ var DbSyncController = class {
4920
4920
  }
4921
4921
  if (plan.status === "up-to-date") return;
4922
4922
  if (!hasChanges) {
4923
- if (!dryRun) await this.runSync(sync, dbTypes, safe);
4923
+ if (!dryRun) {
4924
+ const result = await this.runSync(sync, dbTypes, safe);
4925
+ if (result.entries.some((e) => e.hasErrors)) {
4926
+ this.printer.result(result);
4927
+ this.failOnErrors(result);
4928
+ }
4929
+ }
4924
4930
  return;
4925
4931
  }
4926
4932
  if (dryRun) {
@@ -4937,6 +4943,7 @@ var DbSyncController = class {
4937
4943
  } else this.logger.log(`No destructive changes, proceeding to sync...`);
4938
4944
  const result = await this.runSync(sync, dbTypes, safe);
4939
4945
  this.printer.result(result);
4946
+ this.failOnErrors(result);
4940
4947
  }
4941
4948
  /**
4942
4949
  * Applies the sync. A refused run (`status: 'refused'`) issued no DDL and
@@ -4954,6 +4961,13 @@ var DbSyncController = class {
4954
4961
  return result;
4955
4962
  }
4956
4963
  /**
4964
+ * An applied run that left entries with errors (`status: 'failed'` since
4965
+ * @atscript/db 0.1.170) withheld the schema hash — exit 1 after printing.
4966
+ */ failOnErrors(result) {
4967
+ const errored = result.entries.filter((e) => e.hasErrors).length;
4968
+ if (errored > 0) this.fail(`Schema sync failed for ${errored} ${errored === 1 ? "entry" : "entries"} — see above; the schema hash was not stored.`);
4969
+ }
4970
+ /**
4957
4971
  * Loads the full model inventory or aborts. Diagnostics run first, every
4958
4972
  * generated module is imported individually, and any failure exits 1 before
4959
4973
  * a plan is computed.
@@ -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
@@ -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
@@ -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.7",
4
4
  "description": "Atscript: typescript-gen support.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "peerDependencies": {
76
76
  "@atscript/db": "^0.1.159",
77
- "@atscript/core": "^0.2.6"
77
+ "@atscript/core": "^0.2.7"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@atscript/db": {