@atscript/db 0.1.100 → 0.1.102

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.
Files changed (51) hide show
  1. package/dist/{db-error-yx2jdg8B.mjs → db-error-BHPXOKzc.mjs} +7 -0
  2. package/dist/{db-error-CrtPzaZ-.cjs → db-error-DXwEzmYJ.cjs} +7 -0
  3. package/dist/{db-readable-Cs1-gchT.d.mts → db-readable-CXdHBtF6.d.mts} +1 -1
  4. package/dist/{db-readable-DdY7oFnY.d.cts → db-readable-mhPp-MPv.d.cts} +1 -1
  5. package/dist/{db-space-Bcu7ZzYd.d.mts → db-space-BYyVZnL1.d.mts} +1 -1
  6. package/dist/{db-space-CybVrQAX.d.cts → db-space-BhOc9_OO.d.cts} +1 -1
  7. package/dist/{db-view-BAuda9Rm.cjs → db-view-GcbegVBD.cjs} +10 -7
  8. package/dist/{db-view-D80PwcW5.mjs → db-view-Sq4wCceR.mjs} +8 -5
  9. package/dist/index.cjs +5 -3
  10. package/dist/index.d.cts +5 -5
  11. package/dist/index.d.mts +5 -5
  12. package/dist/index.mjs +5 -3
  13. package/dist/{nested-writer-CVMRAPoF.mjs → nested-writer-DI-HeTky.mjs} +35 -3
  14. package/dist/{nested-writer-Chl_zySG.cjs → nested-writer-DoDhl3X3.cjs} +55 -5
  15. package/dist/ops.cjs +1 -1
  16. package/dist/ops.d.cts +1 -1
  17. package/dist/ops.d.mts +1 -1
  18. package/dist/ops.mjs +1 -1
  19. package/dist/plugin.cjs +1 -1
  20. package/dist/plugin.mjs +1 -1
  21. package/dist/rel.cjs +5 -6
  22. package/dist/rel.d.cts +2 -2
  23. package/dist/rel.d.mts +2 -2
  24. package/dist/rel.mjs +2 -3
  25. package/dist/{relation-loader-BH3AkSnY.mjs → relation-loader-BmeOMj0b.mjs} +1 -1
  26. package/dist/{relation-loader-B8CmCJOs.cjs → relation-loader-Desvk9Ql.cjs} +6 -6
  27. package/dist/shared.cjs +1 -1
  28. package/dist/shared.mjs +1 -1
  29. package/dist/sync.cjs +5 -3
  30. package/dist/sync.d.cts +2 -2
  31. package/dist/sync.d.mts +2 -2
  32. package/dist/sync.mjs +5 -3
  33. package/dist/{validator-DTDf9yWe.mjs → validator-bLsSgi0N.mjs} +1 -1
  34. package/dist/{validator-DrmUaZA3.cjs → validator-f43UcYiY.cjs} +1 -1
  35. package/dist/validator.cjs +1 -1
  36. package/dist/validator.d.cts +4 -4
  37. package/dist/validator.d.mts +4 -4
  38. package/dist/validator.mjs +1 -1
  39. package/package.json +6 -6
  40. package/dist/relation-helpers-BYvsE1tR.cjs +0 -51
  41. package/dist/relation-helpers-CLasawQq.mjs +0 -34
  42. /package/dist/{control-ExEKWYBE.mjs → control-D5cQmzFj.mjs} +0 -0
  43. /package/dist/{control-CDnwVj4q.cjs → control-jIVU2hkf.cjs} +0 -0
  44. /package/dist/{db-validator-plugin-DDvYyv5t.d.mts → db-validator-plugin-BWy60OvG.d.cts} +0 -0
  45. /package/dist/{db-validator-plugin-DRGMCEn3.d.cts → db-validator-plugin-BWy60OvG.d.mts} +0 -0
  46. /package/dist/{ops-Blqr0ipy.d.mts → ops-DJRnNTVo.d.cts} +0 -0
  47. /package/dist/{ops-lzmfzuY9.d.cts → ops-DJRnNTVo.d.mts} +0 -0
  48. /package/dist/{validation-utils-Bs1yOXNx.cjs → validation-utils-CR4H3_nc.cjs} +0 -0
  49. /package/dist/{validation-utils-eaBuT39W.mjs → validation-utils-D4R08oed.mjs} +0 -0
  50. /package/dist/{validator-DttN2e5_.d.mts → validator-Crqe6vRW.d.cts} +0 -0
  51. /package/dist/{validator-_z_A3cKa.d.cts → validator-Crqe6vRW.d.mts} +0 -0
@@ -1,5 +1,7 @@
1
1
  //#region src/db-error.ts
2
2
  var DbError = class extends Error {
3
+ code;
4
+ errors;
3
5
  name = "DbError";
4
6
  constructor(code, errors, message) {
5
7
  super(message ?? errors[0]?.message ?? "Database error");
@@ -13,6 +15,9 @@ var DbError = class extends Error {
13
15
  * declared `@db.depth.limit N`. Surfaced as HTTP 400 in moost-db.
14
16
  */
15
17
  var DepthLimitExceededError = class extends DbError {
18
+ field;
19
+ declared;
20
+ actual;
16
21
  name = "DepthLimitExceededError";
17
22
  constructor(field, declared, actual) {
18
23
  const message = `Nested write depth ${actual} exceeds declared @db.depth.limit ${declared} at '${field}'`;
@@ -32,6 +37,8 @@ var DepthLimitExceededError = class extends DbError {
32
37
  * last-observed version so callers can log/report the contention.
33
38
  */
34
39
  var CasExhaustedError = class extends DbError {
40
+ attempts;
41
+ lastSeenVersion;
35
42
  name = "CasExhaustedError";
36
43
  constructor(attempts, lastSeenVersion) {
37
44
  const message = `Optimistic concurrency: exhausted ${attempts} attempts; row kept changing under us (last seen version: ${lastSeenVersion ?? "unknown"})`;
@@ -1,5 +1,7 @@
1
1
  //#region src/db-error.ts
2
2
  var DbError = class extends Error {
3
+ code;
4
+ errors;
3
5
  name = "DbError";
4
6
  constructor(code, errors, message) {
5
7
  super(message ?? errors[0]?.message ?? "Database error");
@@ -13,6 +15,9 @@ var DbError = class extends Error {
13
15
  * declared `@db.depth.limit N`. Surfaced as HTTP 400 in moost-db.
14
16
  */
15
17
  var DepthLimitExceededError = class extends DbError {
18
+ field;
19
+ declared;
20
+ actual;
16
21
  name = "DepthLimitExceededError";
17
22
  constructor(field, declared, actual) {
18
23
  const message = `Nested write depth ${actual} exceeds declared @db.depth.limit ${declared} at '${field}'`;
@@ -32,6 +37,8 @@ var DepthLimitExceededError = class extends DbError {
32
37
  * last-observed version so callers can log/report the contention.
33
38
  */
34
39
  var CasExhaustedError = class extends DbError {
40
+ attempts;
41
+ lastSeenVersion;
35
42
  name = "CasExhaustedError";
36
43
  constructor(attempts, lastSeenVersion) {
37
44
  const message = `Optimistic concurrency: exhausted ${attempts} attempts; row kept changing under us (last seen version: ${lastSeenVersion ?? "unknown"})`;
@@ -1,4 +1,4 @@
1
- import { f as TFieldOps } from "./ops-Blqr0ipy.mjs";
1
+ import { f as TFieldOps } from "./ops-DJRnNTVo.mjs";
2
2
  import { FlatOf, FlatOf as FlatOf$1, NavPropsOf, NavPropsOf as NavPropsOf$1, OwnPropsOf, OwnPropsOf as OwnPropsOf$1, PrimaryKeyOf, PrimaryKeyOf as PrimaryKeyOf$1, TAtscriptAnnotatedType, TAtscriptDataType, TAtscriptTypeObject, TMetadataMap, TSerializedAnnotatedType, TValidatorOptions, TValidatorPlugin, Validator } from "@atscript/typescript/utils";
3
3
  import { AggregateControls, AggregateExpr, AggregateExpr as AggregateExpr$1, AggregateFn, AggregateQuery, AggregateQuery as AggregateQuery$1, AggregateResult, FieldOpsFor, FilterExpr, FilterExpr as FilterExpr$1, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, UniqueryControls as UniqueryControls$1, UniqueryInsights, WithRelation, WithRelation as WithRelation$1 } from "@uniqu/core";
4
4
 
@@ -1,4 +1,4 @@
1
- import { f as TFieldOps } from "./ops-lzmfzuY9.cjs";
1
+ import { f as TFieldOps } from "./ops-DJRnNTVo.cjs";
2
2
  import { AggregateControls, AggregateExpr, AggregateExpr as AggregateExpr$1, AggregateFn, AggregateQuery, AggregateQuery as AggregateQuery$1, AggregateResult, FieldOpsFor, FilterExpr, FilterExpr as FilterExpr$1, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, UniqueryControls as UniqueryControls$1, UniqueryInsights, WithRelation, WithRelation as WithRelation$1 } from "@uniqu/core";
3
3
  import { FlatOf, FlatOf as FlatOf$1, NavPropsOf, NavPropsOf as NavPropsOf$1, OwnPropsOf, OwnPropsOf as OwnPropsOf$1, PrimaryKeyOf, PrimaryKeyOf as PrimaryKeyOf$1, TAtscriptAnnotatedType, TAtscriptDataType, TAtscriptTypeObject, TMetadataMap, TSerializedAnnotatedType, TValidatorOptions, TValidatorPlugin, Validator } from "@atscript/typescript/utils";
4
4
 
@@ -1,4 +1,4 @@
1
- import { B as TDbInsertResult, J as TFkLookupResolver, N as TDbDeleteResult, W as TDbUpdateResult, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger, t as AtscriptDbReadable, x as TCascadeResolver, z as TDbInsertManyResult } from "./db-readable-Cs1-gchT.mjs";
1
+ import { B as TDbInsertResult, J as TFkLookupResolver, N as TDbDeleteResult, W as TDbUpdateResult, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger, t as AtscriptDbReadable, x as TCascadeResolver, z as TDbInsertManyResult } from "./db-readable-CXdHBtF6.mjs";
2
2
  import { AtscriptQueryComparison, AtscriptQueryFieldRef, AtscriptQueryFieldRef as AtscriptQueryFieldRef$1, AtscriptQueryNode, AtscriptQueryNode as AtscriptQueryNode$1, AtscriptRef, FlatOf, NavPropsOf, OwnPropsOf, PrimaryKeyOf, TAtscriptAnnotatedType, TAtscriptDataType, Validator } from "@atscript/typescript/utils";
3
3
  import { FilterExpr } from "@uniqu/core";
4
4
 
@@ -1,4 +1,4 @@
1
- import { B as TDbInsertResult, J as TFkLookupResolver, N as TDbDeleteResult, W as TDbUpdateResult, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger, t as AtscriptDbReadable, x as TCascadeResolver, z as TDbInsertManyResult } from "./db-readable-DdY7oFnY.cjs";
1
+ import { B as TDbInsertResult, J as TFkLookupResolver, N as TDbDeleteResult, W as TDbUpdateResult, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger, t as AtscriptDbReadable, x as TCascadeResolver, z as TDbInsertManyResult } from "./db-readable-mhPp-MPv.cjs";
2
2
  import { FilterExpr } from "@uniqu/core";
3
3
  import { AtscriptQueryComparison, AtscriptQueryFieldRef, AtscriptQueryFieldRef as AtscriptQueryFieldRef$1, AtscriptQueryNode, AtscriptQueryNode as AtscriptQueryNode$1, AtscriptRef, FlatOf, NavPropsOf, OwnPropsOf, PrimaryKeyOf, TAtscriptAnnotatedType, TAtscriptDataType, Validator } from "@atscript/typescript/utils";
4
4
 
@@ -1,9 +1,8 @@
1
- const require_db_error = require("./db-error-CrtPzaZ-.cjs");
1
+ const require_db_error = require("./db-error-DXwEzmYJ.cjs");
2
2
  const require_agg = require("./agg.cjs");
3
- const require_relation_helpers = require("./relation-helpers-BYvsE1tR.cjs");
3
+ const require_nested_writer = require("./nested-writer-DoDhl3X3.cjs");
4
4
  const require_ops = require("./ops.cjs");
5
- const require_validator = require("./validator-DrmUaZA3.cjs");
6
- const require_nested_writer = require("./nested-writer-Chl_zySG.cjs");
5
+ const require_validator = require("./validator-f43UcYiY.cjs");
7
6
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
8
7
  let node_async_hooks = require("node:async_hooks");
9
8
  //#region src/logger.ts
@@ -1158,6 +1157,10 @@ function isIdCompatible(id, fieldType) {
1158
1157
  * (adds view plan/DDL).
1159
1158
  */
1160
1159
  var AtscriptDbReadable = class {
1160
+ _type;
1161
+ adapter;
1162
+ logger;
1163
+ _tableResolver;
1161
1164
  /** Resolved table/collection/view name. */
1162
1165
  tableName;
1163
1166
  /** Database schema/namespace from `@db.schema` (if set). */
@@ -1712,7 +1715,7 @@ var AtscriptDbReadable = class {
1712
1715
  * Public entry point for relation loading. Used by adapters for nested $with delegation.
1713
1716
  */
1714
1717
  async loadRelations(rows, withRelations) {
1715
- const { loadRelationsImpl } = await Promise.resolve().then(() => require("./relation-loader-B8CmCJOs.cjs")).then((n) => n.relation_loader_exports);
1718
+ const { loadRelationsImpl } = await Promise.resolve().then(() => require("./relation-loader-Desvk9Ql.cjs")).then((n) => n.relation_loader_exports);
1716
1719
  return loadRelationsImpl(rows, withRelations, this);
1717
1720
  }
1718
1721
  /**
@@ -1720,14 +1723,14 @@ var AtscriptDbReadable = class {
1720
1723
  * Thin wrapper — delegates to relation-loader for shared use with db-table.ts write path.
1721
1724
  */
1722
1725
  _findFKForRelation(relation) {
1723
- return require_relation_helpers.findFKForRelation(relation, this._meta.foreignKeys);
1726
+ return require_nested_writer.findFKForRelation(relation, this._meta.foreignKeys);
1724
1727
  }
1725
1728
  /**
1726
1729
  * Finds a FK on a remote table that points back to this table.
1727
1730
  * Thin wrapper — delegates to relation-loader for shared use with db-table.ts write path.
1728
1731
  */
1729
1732
  _findRemoteFK(targetTable, thisTableName, alias) {
1730
- return require_relation_helpers.findRemoteFK(targetTable, thisTableName, alias);
1733
+ return require_nested_writer.findRemoteFK(targetTable, thisTableName, alias);
1731
1734
  }
1732
1735
  };
1733
1736
  //#endregion
@@ -1,9 +1,8 @@
1
- import { n as DbError } from "./db-error-yx2jdg8B.mjs";
1
+ import { n as DbError } from "./db-error-BHPXOKzc.mjs";
2
2
  import { resolveAlias } from "./agg.mjs";
3
- import { n as findRemoteFK, t as findFKForRelation } from "./relation-helpers-CLasawQq.mjs";
3
+ import { a as batchPatchNestedTo, c as batchReplaceNestedTo, d as preValidateNestedFrom, f as validateBatch, g as findRemoteFK, h as findFKForRelation, i as batchPatchNestedFrom, l as batchReplaceNestedVia, m as remapDeleteFkViolation, n as batchInsertNestedTo, o as batchPatchNestedVia, p as enrichFkViolation, r as batchInsertNestedVia, s as batchReplaceNestedFrom, t as batchInsertNestedFrom, u as checkDepthOverflow } from "./nested-writer-DI-HeTky.mjs";
4
4
  import { separateCas, separateFieldOps } from "./ops.mjs";
5
- import { i as forceNavNonOptional, r as dbPlugin, s as getKeyProps, t as buildDbValidator } from "./validator-DTDf9yWe.mjs";
6
- import { a as batchPatchNestedTo, c as batchReplaceNestedTo, d as preValidateNestedFrom, f as validateBatch, i as batchPatchNestedFrom, l as batchReplaceNestedVia, m as remapDeleteFkViolation, n as batchInsertNestedTo, o as batchPatchNestedVia, p as enrichFkViolation, r as batchInsertNestedVia, s as batchReplaceNestedFrom, t as batchInsertNestedFrom, u as checkDepthOverflow } from "./nested-writer-CVMRAPoF.mjs";
5
+ import { i as forceNavNonOptional, r as dbPlugin, s as getKeyProps, t as buildDbValidator } from "./validator-bLsSgi0N.mjs";
7
6
  import { flattenAnnotatedType, isAnnotatedType } from "@atscript/typescript/utils";
8
7
  import { AsyncLocalStorage } from "node:async_hooks";
9
8
  //#region src/logger.ts
@@ -1158,6 +1157,10 @@ function isIdCompatible(id, fieldType) {
1158
1157
  * (adds view plan/DDL).
1159
1158
  */
1160
1159
  var AtscriptDbReadable = class {
1160
+ _type;
1161
+ adapter;
1162
+ logger;
1163
+ _tableResolver;
1161
1164
  /** Resolved table/collection/view name. */
1162
1165
  tableName;
1163
1166
  /** Database schema/namespace from `@db.schema` (if set). */
@@ -1712,7 +1715,7 @@ var AtscriptDbReadable = class {
1712
1715
  * Public entry point for relation loading. Used by adapters for nested $with delegation.
1713
1716
  */
1714
1717
  async loadRelations(rows, withRelations) {
1715
- const { loadRelationsImpl } = await import("./relation-loader-BH3AkSnY.mjs").then((n) => n.n);
1718
+ const { loadRelationsImpl } = await import("./relation-loader-BmeOMj0b.mjs").then((n) => n.n);
1716
1719
  return loadRelationsImpl(rows, withRelations, this);
1717
1720
  }
1718
1721
  /**
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_db_error = require("./db-error-CrtPzaZ-.cjs");
3
- const require_db_view = require("./db-view-BAuda9Rm.cjs");
2
+ const require_db_error = require("./db-error-DXwEzmYJ.cjs");
3
+ const require_db_view = require("./db-view-GcbegVBD.cjs");
4
4
  const require_ops = require("./ops.cjs");
5
- const require_validator = require("./validator-DrmUaZA3.cjs");
5
+ const require_validator = require("./validator-f43UcYiY.cjs");
6
6
  let _uniqu_core = require("@uniqu/core");
7
7
  //#region src/with-optimistic-retry.ts
8
8
  /**
@@ -73,6 +73,8 @@ async function withOptimisticRetry(table, filter, mutator, opts) {
73
73
  * ```
74
74
  */
75
75
  var DbSpace = class {
76
+ adapterFactory;
77
+ logger;
76
78
  _readables = /* @__PURE__ */ new WeakMap();
77
79
  /** All tables created in this space — used for reverse FK lookup during cascade. */
78
80
  _allTables = /* @__PURE__ */ new Set();
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { $ as TMetadataOverrides, A as TDbCollation, B as TDbInsertResult, C as TColumnDiff, D as TDbActionIntent, E as TDbActionInfo, F as TDbForeignKey, G as TExistingColumn, H as TDbRelation, I as TDbIndex, J as TFkLookupResolver, K as TExistingTableOption, L as TDbIndexField, M as TDbDefaultValue, N as TDbDeleteResult, O as TDbActionLevel, P as TDbFieldMeta, Q as TMetaResponse, R as TDbIndexType, S as TCascadeTarget, T as TCrudPermissions, U as TDbStorageType, V as TDbReferentialAction, W as TDbUpdateResult, X as TIdDescriptor, Y as TFkLookupTarget, Z as TIdentification, _ as FlatOf, a as FieldMappingStrategy, at as TValueFormatterPair, b as PrimaryKeyOf, c as AggregateExpr, ct as Uniquery, d as AggregateResult, dt as TableMetadata, et as TRelationInfo, f as AtscriptDbWritable, ft as NoopLogger, g as FilterExpr, h as FieldOpsFor, i as DocumentFieldMapper, it as TTableResolver, j as TDbDefaultFn, k as TDbActionProcessor, l as AggregateFn, lt as UniqueryControls, m as DbQuery, mt as UniquSelect, n as DbResponse, nt as TSyncColumnResult, o as BaseDbAdapter, ot as TWriteTableResolver, p as DbControls, pt as TGenericLogger, q as TFieldMeta, r as resolveDesignType, rt as TTableOptionDiff, s as AggregateControls, st as TypedWithRelation, t as AtscriptDbReadable, tt as TSearchIndexInfo, u as AggregateQuery, ut as WithRelation, v as NavPropsOf, w as TCrudOp, x as TCascadeResolver, y as OwnPropsOf, z as TDbInsertManyResult } from "./db-readable-DdY7oFnY.cjs";
2
- import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-lzmfzuY9.cjs";
3
- import { a as AtscriptQueryComparison, c as AtscriptRef, d as translateQueryTree, f as AtscriptDbTable, i as TViewColumnMapping, l as TViewJoin, m as NativeIntegrity, n as TAdapterFactory, o as AtscriptQueryFieldRef, p as IntegrityStrategy, r as AtscriptDbView, s as AtscriptQueryNode, t as DbSpace, u as TViewPlan } from "./db-space-CybVrQAX.cjs";
4
- import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-DRGMCEn3.cjs";
5
- import { c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-_z_A3cKa.cjs";
1
+ import { $ as TMetadataOverrides, A as TDbCollation, B as TDbInsertResult, C as TColumnDiff, D as TDbActionIntent, E as TDbActionInfo, F as TDbForeignKey, G as TExistingColumn, H as TDbRelation, I as TDbIndex, J as TFkLookupResolver, K as TExistingTableOption, L as TDbIndexField, M as TDbDefaultValue, N as TDbDeleteResult, O as TDbActionLevel, P as TDbFieldMeta, Q as TMetaResponse, R as TDbIndexType, S as TCascadeTarget, T as TCrudPermissions, U as TDbStorageType, V as TDbReferentialAction, W as TDbUpdateResult, X as TIdDescriptor, Y as TFkLookupTarget, Z as TIdentification, _ as FlatOf, a as FieldMappingStrategy, at as TValueFormatterPair, b as PrimaryKeyOf, c as AggregateExpr, ct as Uniquery, d as AggregateResult, dt as TableMetadata, et as TRelationInfo, f as AtscriptDbWritable, ft as NoopLogger, g as FilterExpr, h as FieldOpsFor, i as DocumentFieldMapper, it as TTableResolver, j as TDbDefaultFn, k as TDbActionProcessor, l as AggregateFn, lt as UniqueryControls, m as DbQuery, mt as UniquSelect, n as DbResponse, nt as TSyncColumnResult, o as BaseDbAdapter, ot as TWriteTableResolver, p as DbControls, pt as TGenericLogger, q as TFieldMeta, r as resolveDesignType, rt as TTableOptionDiff, s as AggregateControls, st as TypedWithRelation, t as AtscriptDbReadable, tt as TSearchIndexInfo, u as AggregateQuery, ut as WithRelation, v as NavPropsOf, w as TCrudOp, x as TCascadeResolver, y as OwnPropsOf, z as TDbInsertManyResult } from "./db-readable-mhPp-MPv.cjs";
2
+ import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-DJRnNTVo.cjs";
3
+ import { a as AtscriptQueryComparison, c as AtscriptRef, d as translateQueryTree, f as AtscriptDbTable, i as TViewColumnMapping, l as TViewJoin, m as NativeIntegrity, n as TAdapterFactory, o as AtscriptQueryFieldRef, p as IntegrityStrategy, r as AtscriptDbView, s as AtscriptQueryNode, t as DbSpace, u as TViewPlan } from "./db-space-BhOc9_OO.cjs";
4
+ import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.cjs";
5
+ import { c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-Crqe6vRW.cjs";
6
6
  import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, Uniquery as Uniquery$1, computeInsights, isPrimitive, walkFilter } from "@uniqu/core";
7
7
 
8
8
  //#region src/strategies/relational-field-mapper.d.ts
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { $ as TMetadataOverrides, A as TDbCollation, B as TDbInsertResult, C as TColumnDiff, D as TDbActionIntent, E as TDbActionInfo, F as TDbForeignKey, G as TExistingColumn, H as TDbRelation, I as TDbIndex, J as TFkLookupResolver, K as TExistingTableOption, L as TDbIndexField, M as TDbDefaultValue, N as TDbDeleteResult, O as TDbActionLevel, P as TDbFieldMeta, Q as TMetaResponse, R as TDbIndexType, S as TCascadeTarget, T as TCrudPermissions, U as TDbStorageType, V as TDbReferentialAction, W as TDbUpdateResult, X as TIdDescriptor, Y as TFkLookupTarget, Z as TIdentification, _ as FlatOf, a as FieldMappingStrategy, at as TValueFormatterPair, b as PrimaryKeyOf, c as AggregateExpr, ct as Uniquery, d as AggregateResult, dt as TableMetadata, et as TRelationInfo, f as AtscriptDbWritable, ft as NoopLogger, g as FilterExpr, h as FieldOpsFor, i as DocumentFieldMapper, it as TTableResolver, j as TDbDefaultFn, k as TDbActionProcessor, l as AggregateFn, lt as UniqueryControls, m as DbQuery, mt as UniquSelect, n as DbResponse, nt as TSyncColumnResult, o as BaseDbAdapter, ot as TWriteTableResolver, p as DbControls, pt as TGenericLogger, q as TFieldMeta, r as resolveDesignType, rt as TTableOptionDiff, s as AggregateControls, st as TypedWithRelation, t as AtscriptDbReadable, tt as TSearchIndexInfo, u as AggregateQuery, ut as WithRelation, v as NavPropsOf, w as TCrudOp, x as TCascadeResolver, y as OwnPropsOf, z as TDbInsertManyResult } from "./db-readable-Cs1-gchT.mjs";
2
- import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-Blqr0ipy.mjs";
3
- import { a as AtscriptQueryComparison, c as AtscriptRef, d as translateQueryTree, f as AtscriptDbTable, i as TViewColumnMapping, l as TViewJoin, m as NativeIntegrity, n as TAdapterFactory, o as AtscriptQueryFieldRef, p as IntegrityStrategy, r as AtscriptDbView, s as AtscriptQueryNode, t as DbSpace, u as TViewPlan } from "./db-space-Bcu7ZzYd.mjs";
4
- import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-DDvYyv5t.mjs";
5
- import { c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-DttN2e5_.mjs";
1
+ import { $ as TMetadataOverrides, A as TDbCollation, B as TDbInsertResult, C as TColumnDiff, D as TDbActionIntent, E as TDbActionInfo, F as TDbForeignKey, G as TExistingColumn, H as TDbRelation, I as TDbIndex, J as TFkLookupResolver, K as TExistingTableOption, L as TDbIndexField, M as TDbDefaultValue, N as TDbDeleteResult, O as TDbActionLevel, P as TDbFieldMeta, Q as TMetaResponse, R as TDbIndexType, S as TCascadeTarget, T as TCrudPermissions, U as TDbStorageType, V as TDbReferentialAction, W as TDbUpdateResult, X as TIdDescriptor, Y as TFkLookupTarget, Z as TIdentification, _ as FlatOf, a as FieldMappingStrategy, at as TValueFormatterPair, b as PrimaryKeyOf, c as AggregateExpr, ct as Uniquery, d as AggregateResult, dt as TableMetadata, et as TRelationInfo, f as AtscriptDbWritable, ft as NoopLogger, g as FilterExpr, h as FieldOpsFor, i as DocumentFieldMapper, it as TTableResolver, j as TDbDefaultFn, k as TDbActionProcessor, l as AggregateFn, lt as UniqueryControls, m as DbQuery, mt as UniquSelect, n as DbResponse, nt as TSyncColumnResult, o as BaseDbAdapter, ot as TWriteTableResolver, p as DbControls, pt as TGenericLogger, q as TFieldMeta, r as resolveDesignType, rt as TTableOptionDiff, s as AggregateControls, st as TypedWithRelation, t as AtscriptDbReadable, tt as TSearchIndexInfo, u as AggregateQuery, ut as WithRelation, v as NavPropsOf, w as TCrudOp, x as TCascadeResolver, y as OwnPropsOf, z as TDbInsertManyResult } from "./db-readable-CXdHBtF6.mjs";
2
+ import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-DJRnNTVo.mjs";
3
+ import { a as AtscriptQueryComparison, c as AtscriptRef, d as translateQueryTree, f as AtscriptDbTable, i as TViewColumnMapping, l as TViewJoin, m as NativeIntegrity, n as TAdapterFactory, o as AtscriptQueryFieldRef, p as IntegrityStrategy, r as AtscriptDbView, s as AtscriptQueryNode, t as DbSpace, u as TViewPlan } from "./db-space-BYyVZnL1.mjs";
4
+ import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.mjs";
5
+ import { c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-Crqe6vRW.mjs";
6
6
  import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, Uniquery as Uniquery$1, computeInsights, isPrimitive, walkFilter } from "@uniqu/core";
7
7
 
8
8
  //#region src/strategies/relational-field-mapper.d.ts
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { n as DbError, t as CasExhaustedError } from "./db-error-yx2jdg8B.mjs";
2
- import { a as ApplicationIntegrity, c as NativeIntegrity, d as RelationalFieldMapper, f as DocumentFieldMapper, g as NoopLogger, h as TableMetadata, i as decomposePatch, l as AtscriptDbReadable, m as UniquSelect, n as AtscriptDbTable, o as BaseDbAdapter, p as FieldMappingStrategy, r as assertNoVersionWrites, s as IntegrityStrategy, t as AtscriptDbView, u as resolveDesignType } from "./db-view-D80PwcW5.mjs";
1
+ import { n as DbError, t as CasExhaustedError } from "./db-error-BHPXOKzc.mjs";
2
+ import { a as ApplicationIntegrity, c as NativeIntegrity, d as RelationalFieldMapper, f as DocumentFieldMapper, g as NoopLogger, h as TableMetadata, i as decomposePatch, l as AtscriptDbReadable, m as UniquSelect, n as AtscriptDbTable, o as BaseDbAdapter, p as FieldMappingStrategy, r as assertNoVersionWrites, s as IntegrityStrategy, t as AtscriptDbView, u as resolveDesignType } from "./db-view-Sq4wCceR.mjs";
3
3
  import { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, getDbFieldOp, isDbFieldOp, separateCas, separateFieldOps } from "./ops.mjs";
4
- import { a as isNavRelation, i as forceNavNonOptional, n as buildValidationContext, o as createDbValidatorPlugin, s as getKeyProps, t as buildDbValidator } from "./validator-DTDf9yWe.mjs";
4
+ import { a as isNavRelation, i as forceNavNonOptional, n as buildValidationContext, o as createDbValidatorPlugin, s as getKeyProps, t as buildDbValidator } from "./validator-bLsSgi0N.mjs";
5
5
  import { computeInsights, isPrimitive, walkFilter } from "@uniqu/core";
6
6
  //#region src/with-optimistic-retry.ts
7
7
  /**
@@ -72,6 +72,8 @@ async function withOptimisticRetry(table, filter, mutator, opts) {
72
72
  * ```
73
73
  */
74
74
  var DbSpace = class {
75
+ adapterFactory;
76
+ logger;
75
77
  _readables = /* @__PURE__ */ new WeakMap();
76
78
  /** All tables created in this space — used for reverse FK lookup during cascade. */
77
79
  _allTables = /* @__PURE__ */ new Set();
@@ -1,6 +1,38 @@
1
- import { n as DbError, r as DepthLimitExceededError } from "./db-error-yx2jdg8B.mjs";
2
- import { r as resolveRelationTargetTable } from "./relation-helpers-CLasawQq.mjs";
1
+ import { n as DbError, r as DepthLimitExceededError } from "./db-error-BHPXOKzc.mjs";
3
2
  import { ValidatorError } from "@atscript/typescript/utils";
3
+ //#region src/rel/relation-helpers.ts
4
+ /**
5
+ * Finds the FK entry that connects a `@db.rel.to` relation to its target.
6
+ */
7
+ function findFKForRelation(relation, foreignKeys) {
8
+ const targetTable = resolveRelationTargetTable(relation);
9
+ for (const fk of foreignKeys.values()) if (relation.alias) {
10
+ if (fk.alias === relation.alias) return {
11
+ localFields: fk.fields,
12
+ targetFields: fk.targetFields
13
+ };
14
+ } else if (fk.targetTable === targetTable) return {
15
+ localFields: fk.fields,
16
+ targetFields: fk.targetFields
17
+ };
18
+ }
19
+ /**
20
+ * Finds a FK on a remote table that points back to a given table name.
21
+ */
22
+ function findRemoteFK(targetTable, thisTableName, alias) {
23
+ for (const fk of targetTable.foreignKeys.values()) {
24
+ if (alias && fk.alias === alias && fk.targetTable === thisTableName) return fk;
25
+ if (!alias && fk.targetTable === thisTableName) return fk;
26
+ }
27
+ }
28
+ /**
29
+ * Resolves the target table name from a relation's target type metadata.
30
+ */
31
+ function resolveRelationTargetTable(relation) {
32
+ const targetType = relation.targetType();
33
+ return targetType?.metadata?.get("db.table") || targetType?.id || "";
34
+ }
35
+ //#endregion
4
36
  //#region src/table/error-utils.ts
5
37
  /**
6
38
  * Prefixes error paths with a nav field context.
@@ -614,4 +646,4 @@ async function viaReplace(targetTable, junctionTable, targets, parentPK, targetP
614
646
  }
615
647
  }
616
648
  //#endregion
617
- export { batchPatchNestedTo as a, batchReplaceNestedTo as c, preValidateNestedFrom as d, validateBatch as f, batchPatchNestedFrom as i, batchReplaceNestedVia as l, remapDeleteFkViolation as m, batchInsertNestedTo as n, batchPatchNestedVia as o, enrichFkViolation as p, batchInsertNestedVia as r, batchReplaceNestedFrom as s, batchInsertNestedFrom as t, checkDepthOverflow as u };
649
+ export { resolveRelationTargetTable as _, batchPatchNestedTo as a, batchReplaceNestedTo as c, preValidateNestedFrom as d, validateBatch as f, findRemoteFK as g, findFKForRelation as h, batchPatchNestedFrom as i, batchReplaceNestedVia as l, remapDeleteFkViolation as m, batchInsertNestedTo as n, batchPatchNestedVia as o, enrichFkViolation as p, batchInsertNestedVia as r, batchReplaceNestedFrom as s, batchInsertNestedFrom as t, checkDepthOverflow as u };
@@ -1,6 +1,38 @@
1
- const require_db_error = require("./db-error-CrtPzaZ-.cjs");
2
- const require_relation_helpers = require("./relation-helpers-BYvsE1tR.cjs");
1
+ const require_db_error = require("./db-error-DXwEzmYJ.cjs");
3
2
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
3
+ //#region src/rel/relation-helpers.ts
4
+ /**
5
+ * Finds the FK entry that connects a `@db.rel.to` relation to its target.
6
+ */
7
+ function findFKForRelation(relation, foreignKeys) {
8
+ const targetTable = resolveRelationTargetTable(relation);
9
+ for (const fk of foreignKeys.values()) if (relation.alias) {
10
+ if (fk.alias === relation.alias) return {
11
+ localFields: fk.fields,
12
+ targetFields: fk.targetFields
13
+ };
14
+ } else if (fk.targetTable === targetTable) return {
15
+ localFields: fk.fields,
16
+ targetFields: fk.targetFields
17
+ };
18
+ }
19
+ /**
20
+ * Finds a FK on a remote table that points back to a given table name.
21
+ */
22
+ function findRemoteFK(targetTable, thisTableName, alias) {
23
+ for (const fk of targetTable.foreignKeys.values()) {
24
+ if (alias && fk.alias === alias && fk.targetTable === thisTableName) return fk;
25
+ if (!alias && fk.targetTable === thisTableName) return fk;
26
+ }
27
+ }
28
+ /**
29
+ * Resolves the target table name from a relation's target type metadata.
30
+ */
31
+ function resolveRelationTargetTable(relation) {
32
+ const targetType = relation.targetType();
33
+ return targetType?.metadata?.get("db.table") || targetType?.id || "";
34
+ }
35
+ //#endregion
4
36
  //#region src/table/error-utils.ts
5
37
  /**
6
38
  * Prefixes error paths with a nav field context.
@@ -180,7 +212,7 @@ async function batchInsertNestedVia(host, originals, parentIds, maxDepth, depth)
180
212
  if (!targetTable) continue;
181
213
  const junctionTable = host._writeTableResolver(relation.viaType());
182
214
  if (!junctionTable) continue;
183
- const targetTableName = require_relation_helpers.resolveRelationTargetTable(relation);
215
+ const targetTableName = resolveRelationTargetTable(relation);
184
216
  const fkToThis = host._findRemoteFK(junctionTable, host.tableName);
185
217
  if (!fkToThis) continue;
186
218
  const fkToTarget = host._findRemoteFK(junctionTable, targetTableName);
@@ -275,7 +307,7 @@ async function batchReplaceNestedVia(host, originals, maxDepth, depth) {
275
307
  if (!targetTable) continue;
276
308
  const junctionTable = host._writeTableResolver(relation.viaType());
277
309
  if (!junctionTable) continue;
278
- const targetTableName = require_relation_helpers.resolveRelationTargetTable(relation);
310
+ const targetTableName = resolveRelationTargetTable(relation);
279
311
  const fkToThis = host._findRemoteFK(junctionTable, host.tableName);
280
312
  if (!fkToThis) continue;
281
313
  const fkToTarget = host._findRemoteFK(junctionTable, targetTableName);
@@ -420,7 +452,7 @@ async function batchPatchNestedVia(host, originals, maxDepth, depth) {
420
452
  if (!targetTable) continue;
421
453
  const junctionTable = host._writeTableResolver(relation.viaType());
422
454
  if (!junctionTable) continue;
423
- const targetTableName = require_relation_helpers.resolveRelationTargetTable(relation);
455
+ const targetTableName = resolveRelationTargetTable(relation);
424
456
  const fkToThis = host._findRemoteFK(junctionTable, host.tableName);
425
457
  if (!fkToThis) continue;
426
458
  const fkToTarget = host._findRemoteFK(junctionTable, targetTableName);
@@ -680,6 +712,18 @@ Object.defineProperty(exports, "enrichFkViolation", {
680
712
  return enrichFkViolation;
681
713
  }
682
714
  });
715
+ Object.defineProperty(exports, "findFKForRelation", {
716
+ enumerable: true,
717
+ get: function() {
718
+ return findFKForRelation;
719
+ }
720
+ });
721
+ Object.defineProperty(exports, "findRemoteFK", {
722
+ enumerable: true,
723
+ get: function() {
724
+ return findRemoteFK;
725
+ }
726
+ });
683
727
  Object.defineProperty(exports, "preValidateNestedFrom", {
684
728
  enumerable: true,
685
729
  get: function() {
@@ -692,6 +736,12 @@ Object.defineProperty(exports, "remapDeleteFkViolation", {
692
736
  return remapDeleteFkViolation;
693
737
  }
694
738
  });
739
+ Object.defineProperty(exports, "resolveRelationTargetTable", {
740
+ enumerable: true,
741
+ get: function() {
742
+ return resolveRelationTargetTable;
743
+ }
744
+ });
695
745
  Object.defineProperty(exports, "validateBatch", {
696
746
  enumerable: true,
697
747
  get: function() {
package/dist/ops.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_db_error = require("./db-error-CrtPzaZ-.cjs");
2
+ const require_db_error = require("./db-error-DXwEzmYJ.cjs");
3
3
  //#region src/ops.ts
4
4
  /** Increment a numeric field by `value` (default 1). */
5
5
  function $inc(value = 1) {
package/dist/ops.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-lzmfzuY9.cjs";
1
+ import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-DJRnNTVo.cjs";
2
2
  export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, TDbCas, TDbFieldOp, TFieldOps, getDbFieldOp, isDbFieldOp, separateCas, separateFieldOps };
package/dist/ops.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-Blqr0ipy.mjs";
1
+ import { a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateFieldOps, h as separateCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-DJRnNTVo.mjs";
2
2
  export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, TDbCas, TDbFieldOp, TFieldOps, getDbFieldOp, isDbFieldOp, separateCas, separateFieldOps };
package/dist/ops.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as DbError } from "./db-error-yx2jdg8B.mjs";
1
+ import { n as DbError } from "./db-error-BHPXOKzc.mjs";
2
2
  //#region src/ops.ts
3
3
  /** Increment a numeric field by `value` (default 1). */
4
4
  function $inc(value = 1) {
package/dist/plugin.cjs CHANGED
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_validation_utils = require("./validation-utils-Bs1yOXNx.cjs");
5
+ const require_validation_utils = require("./validation-utils-CR4H3_nc.cjs");
6
6
  let _atscript_core = require("@atscript/core");
7
7
  //#region src/plugin/annotations/agg.ts
8
8
  const dbAggAnnotations = { agg: {
package/dist/plugin.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as getAnnotationAlias, c as getParentStruct, d as validateExclusiveWith, f as validateFieldBaseType, i as validateRefArgument, l as getParentTypeName, n as hasAnyViewAnnotation, o as getDbTableOwner, p as validateSiblingStringField, r as validateQueryScope, s as getNavTargetTypeName, t as findFKFieldsPointingTo, u as refActionAnnotation } from "./validation-utils-eaBuT39W.mjs";
1
+ import { a as getAnnotationAlias, c as getParentStruct, d as validateExclusiveWith, f as validateFieldBaseType, i as validateRefArgument, l as getParentTypeName, n as hasAnyViewAnnotation, o as getDbTableOwner, p as validateSiblingStringField, r as validateQueryScope, s as getNavTargetTypeName, t as findFKFieldsPointingTo, u as refActionAnnotation } from "./validation-utils-D4R08oed.mjs";
2
2
  import { AnnotationSpec, isArray, isInterface, isPrimitive, isRef, isStructure } from "@atscript/core";
3
3
  //#region src/plugin/annotations/agg.ts
4
4
  const dbAggAnnotations = { agg: {
package/dist/rel.cjs CHANGED
@@ -1,7 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_relation_loader = require("./relation-loader-B8CmCJOs.cjs");
3
- const require_relation_helpers = require("./relation-helpers-BYvsE1tR.cjs");
4
- const require_nested_writer = require("./nested-writer-Chl_zySG.cjs");
2
+ const require_relation_loader = require("./relation-loader-Desvk9Ql.cjs");
3
+ const require_nested_writer = require("./nested-writer-DoDhl3X3.cjs");
5
4
  exports.batchInsertNestedFrom = require_nested_writer.batchInsertNestedFrom;
6
5
  exports.batchInsertNestedTo = require_nested_writer.batchInsertNestedTo;
7
6
  exports.batchInsertNestedVia = require_nested_writer.batchInsertNestedVia;
@@ -12,9 +11,9 @@ exports.batchReplaceNestedFrom = require_nested_writer.batchReplaceNestedFrom;
12
11
  exports.batchReplaceNestedTo = require_nested_writer.batchReplaceNestedTo;
13
12
  exports.batchReplaceNestedVia = require_nested_writer.batchReplaceNestedVia;
14
13
  exports.checkDepthOverflow = require_nested_writer.checkDepthOverflow;
15
- exports.findFKForRelation = require_relation_helpers.findFKForRelation;
16
- exports.findRemoteFK = require_relation_helpers.findRemoteFK;
14
+ exports.findFKForRelation = require_nested_writer.findFKForRelation;
15
+ exports.findRemoteFK = require_nested_writer.findRemoteFK;
17
16
  exports.loadRelationsImpl = require_relation_loader.loadRelationsImpl;
18
17
  exports.preValidateNestedFrom = require_nested_writer.preValidateNestedFrom;
19
- exports.resolveRelationTargetTable = require_relation_helpers.resolveRelationTargetTable;
18
+ exports.resolveRelationTargetTable = require_nested_writer.resolveRelationTargetTable;
20
19
  exports.validateBatch = require_nested_writer.validateBatch;
package/dist/rel.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as TDbForeignKey, H as TDbRelation, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger } from "./db-readable-DdY7oFnY.cjs";
2
- import { t as DbValidationContext } from "./db-validator-plugin-DRGMCEn3.cjs";
1
+ import { F as TDbForeignKey, H as TDbRelation, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger } from "./db-readable-mhPp-MPv.cjs";
2
+ import { t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.cjs";
3
3
  import { FilterExpr, WithRelation } from "@uniqu/core";
4
4
  import { Validator } from "@atscript/typescript/utils";
5
5
 
package/dist/rel.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as TDbForeignKey, H as TDbRelation, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger } from "./db-readable-Cs1-gchT.mjs";
2
- import { t as DbValidationContext } from "./db-validator-plugin-DDvYyv5t.mjs";
1
+ import { F as TDbForeignKey, H as TDbRelation, dt as TableMetadata, it as TTableResolver, o as BaseDbAdapter, ot as TWriteTableResolver, pt as TGenericLogger } from "./db-readable-CXdHBtF6.mjs";
2
+ import { t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.mjs";
3
3
  import { Validator } from "@atscript/typescript/utils";
4
4
  import { FilterExpr, WithRelation } from "@uniqu/core";
5
5
 
package/dist/rel.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { t as loadRelationsImpl } from "./relation-loader-BH3AkSnY.mjs";
2
- import { n as findRemoteFK, r as resolveRelationTargetTable, t as findFKForRelation } from "./relation-helpers-CLasawQq.mjs";
3
- import { a as batchPatchNestedTo, c as batchReplaceNestedTo, d as preValidateNestedFrom, f as validateBatch, i as batchPatchNestedFrom, l as batchReplaceNestedVia, n as batchInsertNestedTo, o as batchPatchNestedVia, r as batchInsertNestedVia, s as batchReplaceNestedFrom, t as batchInsertNestedFrom, u as checkDepthOverflow } from "./nested-writer-CVMRAPoF.mjs";
1
+ import { t as loadRelationsImpl } from "./relation-loader-BmeOMj0b.mjs";
2
+ import { _ as resolveRelationTargetTable, a as batchPatchNestedTo, c as batchReplaceNestedTo, d as preValidateNestedFrom, f as validateBatch, g as findRemoteFK, h as findFKForRelation, i as batchPatchNestedFrom, l as batchReplaceNestedVia, n as batchInsertNestedTo, o as batchPatchNestedVia, r as batchInsertNestedVia, s as batchReplaceNestedFrom, t as batchInsertNestedFrom, u as checkDepthOverflow } from "./nested-writer-DI-HeTky.mjs";
4
3
  export { batchInsertNestedFrom, batchInsertNestedTo, batchInsertNestedVia, batchPatchNestedFrom, batchPatchNestedTo, batchPatchNestedVia, batchReplaceNestedFrom, batchReplaceNestedTo, batchReplaceNestedVia, checkDepthOverflow, findFKForRelation, findRemoteFK, loadRelationsImpl, preValidateNestedFrom, resolveRelationTargetTable, validateBatch };
@@ -1,4 +1,4 @@
1
- import { n as findRemoteFK, r as resolveRelationTargetTable, t as findFKForRelation } from "./relation-helpers-CLasawQq.mjs";
1
+ import { _ as resolveRelationTargetTable, g as findRemoteFK, h as findFKForRelation } from "./nested-writer-DI-HeTky.mjs";
2
2
  //#region \0rolldown/runtime.js
3
3
  var __defProp = Object.defineProperty;
4
4
  var __exportAll = (all, no_symbols) => {
@@ -10,7 +10,7 @@ var __exportAll = (all, no_symbols) => {
10
10
  return target;
11
11
  };
12
12
  //#endregion
13
- const require_relation_helpers = require("./relation-helpers-BYvsE1tR.cjs");
13
+ const require_nested_writer = require("./nested-writer-DoDhl3X3.cjs");
14
14
  //#region src/rel/relation-loader.ts
15
15
  var relation_loader_exports = /* @__PURE__ */ __exportAll({
16
16
  ensureSelectIncludesFields: () => ensureSelectIncludesFields,
@@ -74,7 +74,7 @@ async function loadRelationsImpl(rows, withRelations, host) {
74
74
  */
75
75
  async function loadToRelation(rows, opts, host) {
76
76
  const { relName, relation, targetTable, relQuery } = opts;
77
- const fkEntry = require_relation_helpers.findFKForRelation(relation, host._meta.foreignKeys);
77
+ const fkEntry = require_nested_writer.findFKForRelation(relation, host._meta.foreignKeys);
78
78
  if (!fkEntry) return;
79
79
  const { localFields, targetFields } = fkEntry;
80
80
  if (localFields.length === 1) {
@@ -115,7 +115,7 @@ async function loadToRelation(rows, opts, host) {
115
115
  */
116
116
  async function loadFromRelation(rows, opts, host) {
117
117
  const { relName, relation, targetTable, relQuery } = opts;
118
- const remoteFK = require_relation_helpers.findRemoteFK(targetTable, host.tableName, relation.alias);
118
+ const remoteFK = require_nested_writer.findRemoteFK(targetTable, host.tableName, relation.alias);
119
119
  if (!remoteFK) {
120
120
  host.logger.warn(`Could not find FK on target table for relation "${relName}"`);
121
121
  return;
@@ -190,13 +190,13 @@ async function loadViaRelation(rows, opts, host) {
190
190
  host.logger.warn(`Could not resolve junction table for via relation "${relName}"`);
191
191
  return;
192
192
  }
193
- const fkToThis = require_relation_helpers.findRemoteFK(junctionTable, host.tableName);
193
+ const fkToThis = require_nested_writer.findRemoteFK(junctionTable, host.tableName);
194
194
  if (!fkToThis) {
195
195
  host.logger.warn(`Could not find FK on junction table pointing to "${host.tableName}" for via relation "${relName}"`);
196
196
  return;
197
197
  }
198
- const targetTableName = require_relation_helpers.resolveRelationTargetTable(relation);
199
- const fkToTarget = require_relation_helpers.findRemoteFK(junctionTable, targetTableName);
198
+ const targetTableName = require_nested_writer.resolveRelationTargetTable(relation);
199
+ const fkToTarget = require_nested_writer.findRemoteFK(junctionTable, targetTableName);
200
200
  if (!fkToTarget) {
201
201
  host.logger.warn(`Could not find FK on junction table pointing to target "${targetTableName}" for via relation "${relName}"`);
202
202
  return;
package/dist/shared.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_validation_utils = require("./validation-utils-Bs1yOXNx.cjs");
2
+ const require_validation_utils = require("./validation-utils-CR4H3_nc.cjs");
3
3
  exports.findFKFieldsPointingTo = require_validation_utils.findFKFieldsPointingTo;
4
4
  exports.getAnnotationAlias = require_validation_utils.getAnnotationAlias;
5
5
  exports.getDbTableOwner = require_validation_utils.getDbTableOwner;
package/dist/shared.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as getAnnotationAlias, c as getParentStruct, d as validateExclusiveWith, f as validateFieldBaseType, i as validateRefArgument, l as getParentTypeName, n as hasAnyViewAnnotation, o as getDbTableOwner, p as validateSiblingStringField, r as validateQueryScope, s as getNavTargetTypeName, t as findFKFieldsPointingTo, u as refActionAnnotation } from "./validation-utils-eaBuT39W.mjs";
1
+ import { a as getAnnotationAlias, c as getParentStruct, d as validateExclusiveWith, f as validateFieldBaseType, i as validateRefArgument, l as getParentTypeName, n as hasAnyViewAnnotation, o as getDbTableOwner, p as validateSiblingStringField, r as validateQueryScope, s as getNavTargetTypeName, t as findFKFieldsPointingTo, u as refActionAnnotation } from "./validation-utils-D4R08oed.mjs";
2
2
  export { findFKFieldsPointingTo, getAnnotationAlias, getDbTableOwner, getNavTargetTypeName, getParentStruct, getParentTypeName, hasAnyViewAnnotation, refActionAnnotation, validateExclusiveWith, validateFieldBaseType, validateQueryScope, validateRefArgument, validateSiblingStringField };
package/dist/sync.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_db_view = require("./db-view-BAuda9Rm.cjs");
2
+ const require_db_view = require("./db-view-GcbegVBD.cjs");
3
3
  //#region src/schema/schema-hash.ts
4
4
  /** Extracts sorted field snapshots from a readable's field descriptors. */
5
5
  function extractFieldSnapshots(fields, typeMapper) {
@@ -277,13 +277,14 @@ function computeTableOptionDiff(desired, existing, destructiveKeys) {
277
277
  //#endregion
278
278
  //#region src/schema/sync-store.ts
279
279
  var SyncStore = class {
280
+ space;
280
281
  controlTable;
281
282
  constructor(space) {
282
283
  this.space = space;
283
284
  }
284
285
  async ensureControlTable() {
285
286
  if (!this.controlTable) {
286
- const { AtscriptControl } = await Promise.resolve().then(() => require("./control-CDnwVj4q.cjs"));
287
+ const { AtscriptControl } = await Promise.resolve().then(() => require("./control-jIVU2hkf.cjs"));
287
288
  this.controlTable = this.space.getTable(AtscriptControl);
288
289
  }
289
290
  await this.controlTable.ensureTable();
@@ -419,7 +420,7 @@ var SyncStore = class {
419
420
  }
420
421
  };
421
422
  async function readStoredSnapshot(space, tableName, _asView) {
422
- const { AtscriptControl } = await Promise.resolve().then(() => require("./control-CDnwVj4q.cjs"));
423
+ const { AtscriptControl } = await Promise.resolve().then(() => require("./control-jIVU2hkf.cjs"));
423
424
  const table = space.getTable(AtscriptControl);
424
425
  await table.ensureTable();
425
426
  const value = (await table.findOne({
@@ -765,6 +766,7 @@ function buildFkChangeDetails(desired, existing) {
765
766
  return parts.join(", ");
766
767
  }
767
768
  var SchemaSync = class {
769
+ space;
768
770
  store;
769
771
  logger;
770
772
  constructor(space, logger) {
package/dist/sync.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as TColumnDiff, F as TDbForeignKey, G as TExistingColumn, K as TExistingTableOption, M as TDbDefaultValue, P as TDbFieldMeta, U as TDbStorageType, pt as TGenericLogger, rt as TTableOptionDiff, t as AtscriptDbReadable } from "./db-readable-DdY7oFnY.cjs";
2
- import { r as AtscriptDbView, t as DbSpace } from "./db-space-CybVrQAX.cjs";
1
+ import { C as TColumnDiff, F as TDbForeignKey, G as TExistingColumn, K as TExistingTableOption, M as TDbDefaultValue, P as TDbFieldMeta, U as TDbStorageType, pt as TGenericLogger, rt as TTableOptionDiff, t as AtscriptDbReadable } from "./db-readable-mhPp-MPv.cjs";
2
+ import { r as AtscriptDbView, t as DbSpace } from "./db-space-BhOc9_OO.cjs";
3
3
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
4
 
5
5
  //#region src/schema/sync-entry.d.ts
package/dist/sync.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as TColumnDiff, F as TDbForeignKey, G as TExistingColumn, K as TExistingTableOption, M as TDbDefaultValue, P as TDbFieldMeta, U as TDbStorageType, pt as TGenericLogger, rt as TTableOptionDiff, t as AtscriptDbReadable } from "./db-readable-Cs1-gchT.mjs";
2
- import { r as AtscriptDbView, t as DbSpace } from "./db-space-Bcu7ZzYd.mjs";
1
+ import { C as TColumnDiff, F as TDbForeignKey, G as TExistingColumn, K as TExistingTableOption, M as TDbDefaultValue, P as TDbFieldMeta, U as TDbStorageType, pt as TGenericLogger, rt as TTableOptionDiff, t as AtscriptDbReadable } from "./db-readable-CXdHBtF6.mjs";
2
+ import { r as AtscriptDbView, t as DbSpace } from "./db-space-BYyVZnL1.mjs";
3
3
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
4
4
 
5
5
  //#region src/schema/sync-entry.d.ts
package/dist/sync.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as NoopLogger } from "./db-view-D80PwcW5.mjs";
1
+ import { g as NoopLogger } from "./db-view-Sq4wCceR.mjs";
2
2
  //#region src/schema/schema-hash.ts
3
3
  /** Extracts sorted field snapshots from a readable's field descriptors. */
4
4
  function extractFieldSnapshots(fields, typeMapper) {
@@ -276,13 +276,14 @@ function computeTableOptionDiff(desired, existing, destructiveKeys) {
276
276
  //#endregion
277
277
  //#region src/schema/sync-store.ts
278
278
  var SyncStore = class {
279
+ space;
279
280
  controlTable;
280
281
  constructor(space) {
281
282
  this.space = space;
282
283
  }
283
284
  async ensureControlTable() {
284
285
  if (!this.controlTable) {
285
- const { AtscriptControl } = await import("./control-ExEKWYBE.mjs");
286
+ const { AtscriptControl } = await import("./control-D5cQmzFj.mjs");
286
287
  this.controlTable = this.space.getTable(AtscriptControl);
287
288
  }
288
289
  await this.controlTable.ensureTable();
@@ -418,7 +419,7 @@ var SyncStore = class {
418
419
  }
419
420
  };
420
421
  async function readStoredSnapshot(space, tableName, _asView) {
421
- const { AtscriptControl } = await import("./control-ExEKWYBE.mjs");
422
+ const { AtscriptControl } = await import("./control-D5cQmzFj.mjs");
422
423
  const table = space.getTable(AtscriptControl);
423
424
  await table.ensureTable();
424
425
  const value = (await table.findOne({
@@ -764,6 +765,7 @@ function buildFkChangeDetails(desired, existing) {
764
765
  return parts.join(", ");
765
766
  }
766
767
  var SchemaSync = class {
768
+ space;
767
769
  store;
768
770
  logger;
769
771
  constructor(space, logger) {
@@ -1,4 +1,4 @@
1
- import { r as DepthLimitExceededError } from "./db-error-yx2jdg8B.mjs";
1
+ import { r as DepthLimitExceededError } from "./db-error-BHPXOKzc.mjs";
2
2
  import { isDbFieldOp } from "./ops.mjs";
3
3
  import { flattenAnnotatedType } from "@atscript/typescript/utils";
4
4
  //#region src/patch/patch-types.ts
@@ -1,4 +1,4 @@
1
- const require_db_error = require("./db-error-CrtPzaZ-.cjs");
1
+ const require_db_error = require("./db-error-DXwEzmYJ.cjs");
2
2
  const require_ops = require("./ops.cjs");
3
3
  let _atscript_typescript_utils = require("@atscript/typescript/utils");
4
4
  //#region src/patch/patch-types.ts
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_ops = require("./ops.cjs");
3
- const require_validator = require("./validator-DrmUaZA3.cjs");
3
+ const require_validator = require("./validator-f43UcYiY.cjs");
4
4
  exports.$cas = require_ops.$cas;
5
5
  exports.$dec = require_ops.$dec;
6
6
  exports.$inc = require_ops.$inc;
@@ -1,4 +1,4 @@
1
- import { a as $mul, c as $update, d as TDbFieldOp, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-lzmfzuY9.cjs";
2
- import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-DRGMCEn3.cjs";
3
- import { a as dbPlugin, c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-_z_A3cKa.cjs";
4
- export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, DbValidationContext, TArrayPatch, TDbCas, TDbFieldOp, TDbPatch, ValidationContext, ValidatorMode, buildDbValidator, buildValidationContext, createDbValidatorPlugin, dbPlugin, forceNavNonOptional, getKeyProps, isDbFieldOp, isNavRelation };
1
+ import { a as $mul, c as $update, d as TDbFieldOp, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-DJRnNTVo.cjs";
2
+ import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.cjs";
3
+ import { a as dbPlugin, c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-Crqe6vRW.cjs";
4
+ export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, type DbValidationContext, type TArrayPatch, type TDbCas, type TDbFieldOp, type TDbPatch, ValidationContext, ValidatorMode, buildDbValidator, buildValidationContext, createDbValidatorPlugin, dbPlugin, forceNavNonOptional, getKeyProps, isDbFieldOp, isNavRelation };
@@ -1,4 +1,4 @@
1
- import { a as $mul, c as $update, d as TDbFieldOp, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-Blqr0ipy.mjs";
2
- import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-DDvYyv5t.mjs";
3
- import { a as dbPlugin, c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-DttN2e5_.mjs";
4
- export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, DbValidationContext, TArrayPatch, TDbCas, TDbFieldOp, TDbPatch, ValidationContext, ValidatorMode, buildDbValidator, buildValidationContext, createDbValidatorPlugin, dbPlugin, forceNavNonOptional, getKeyProps, isDbFieldOp, isNavRelation };
1
+ import { a as $mul, c as $update, d as TDbFieldOp, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-DJRnNTVo.mjs";
2
+ import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.mjs";
3
+ import { a as dbPlugin, c as TArrayPatch, i as buildValidationContext, l as TDbPatch, n as ValidatorMode, o as forceNavNonOptional, r as buildDbValidator, s as isNavRelation, t as ValidationContext, u as getKeyProps } from "./validator-Crqe6vRW.mjs";
4
+ export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, type DbValidationContext, type TArrayPatch, type TDbCas, type TDbFieldOp, type TDbPatch, ValidationContext, ValidatorMode, buildDbValidator, buildValidationContext, createDbValidatorPlugin, dbPlugin, forceNavNonOptional, getKeyProps, isDbFieldOp, isNavRelation };
@@ -1,3 +1,3 @@
1
1
  import { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, isDbFieldOp } from "./ops.mjs";
2
- import { a as isNavRelation, i as forceNavNonOptional, n as buildValidationContext, o as createDbValidatorPlugin, r as dbPlugin, s as getKeyProps, t as buildDbValidator } from "./validator-DTDf9yWe.mjs";
2
+ import { a as isNavRelation, i as forceNavNonOptional, n as buildValidationContext, o as createDbValidatorPlugin, r as dbPlugin, s as getKeyProps, t as buildDbValidator } from "./validator-bLsSgi0N.mjs";
3
3
  export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, buildDbValidator, buildValidationContext, createDbValidatorPlugin, dbPlugin, forceNavNonOptional, getKeyProps, isDbFieldOp, isNavRelation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db",
3
- "version": "0.1.100",
3
+ "version": "0.1.102",
4
4
  "description": "Database adapter utilities for atscript.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -71,14 +71,14 @@
71
71
  "access": "public"
72
72
  },
73
73
  "devDependencies": {
74
- "@atscript/core": "^0.1.73",
75
- "@atscript/typescript": "^0.1.73",
74
+ "@atscript/core": "^0.1.74",
75
+ "@atscript/typescript": "^0.1.74",
76
76
  "@uniqu/core": "^0.1.6",
77
- "unplugin-atscript": "^0.1.73"
77
+ "unplugin-atscript": "^0.1.74"
78
78
  },
79
79
  "peerDependencies": {
80
- "@atscript/core": "^0.1.73",
81
- "@atscript/typescript": "^0.1.73",
80
+ "@atscript/core": "^0.1.74",
81
+ "@atscript/typescript": "^0.1.74",
82
82
  "@uniqu/core": "^0.1.6"
83
83
  },
84
84
  "scripts": {
@@ -1,51 +0,0 @@
1
- //#region src/rel/relation-helpers.ts
2
- /**
3
- * Finds the FK entry that connects a `@db.rel.to` relation to its target.
4
- */
5
- function findFKForRelation(relation, foreignKeys) {
6
- const targetTable = resolveRelationTargetTable(relation);
7
- for (const fk of foreignKeys.values()) if (relation.alias) {
8
- if (fk.alias === relation.alias) return {
9
- localFields: fk.fields,
10
- targetFields: fk.targetFields
11
- };
12
- } else if (fk.targetTable === targetTable) return {
13
- localFields: fk.fields,
14
- targetFields: fk.targetFields
15
- };
16
- }
17
- /**
18
- * Finds a FK on a remote table that points back to a given table name.
19
- */
20
- function findRemoteFK(targetTable, thisTableName, alias) {
21
- for (const fk of targetTable.foreignKeys.values()) {
22
- if (alias && fk.alias === alias && fk.targetTable === thisTableName) return fk;
23
- if (!alias && fk.targetTable === thisTableName) return fk;
24
- }
25
- }
26
- /**
27
- * Resolves the target table name from a relation's target type metadata.
28
- */
29
- function resolveRelationTargetTable(relation) {
30
- const targetType = relation.targetType();
31
- return targetType?.metadata?.get("db.table") || targetType?.id || "";
32
- }
33
- //#endregion
34
- Object.defineProperty(exports, "findFKForRelation", {
35
- enumerable: true,
36
- get: function() {
37
- return findFKForRelation;
38
- }
39
- });
40
- Object.defineProperty(exports, "findRemoteFK", {
41
- enumerable: true,
42
- get: function() {
43
- return findRemoteFK;
44
- }
45
- });
46
- Object.defineProperty(exports, "resolveRelationTargetTable", {
47
- enumerable: true,
48
- get: function() {
49
- return resolveRelationTargetTable;
50
- }
51
- });
@@ -1,34 +0,0 @@
1
- //#region src/rel/relation-helpers.ts
2
- /**
3
- * Finds the FK entry that connects a `@db.rel.to` relation to its target.
4
- */
5
- function findFKForRelation(relation, foreignKeys) {
6
- const targetTable = resolveRelationTargetTable(relation);
7
- for (const fk of foreignKeys.values()) if (relation.alias) {
8
- if (fk.alias === relation.alias) return {
9
- localFields: fk.fields,
10
- targetFields: fk.targetFields
11
- };
12
- } else if (fk.targetTable === targetTable) return {
13
- localFields: fk.fields,
14
- targetFields: fk.targetFields
15
- };
16
- }
17
- /**
18
- * Finds a FK on a remote table that points back to a given table name.
19
- */
20
- function findRemoteFK(targetTable, thisTableName, alias) {
21
- for (const fk of targetTable.foreignKeys.values()) {
22
- if (alias && fk.alias === alias && fk.targetTable === thisTableName) return fk;
23
- if (!alias && fk.targetTable === thisTableName) return fk;
24
- }
25
- }
26
- /**
27
- * Resolves the target table name from a relation's target type metadata.
28
- */
29
- function resolveRelationTargetTable(relation) {
30
- const targetType = relation.targetType();
31
- return targetType?.metadata?.get("db.table") || targetType?.id || "";
32
- }
33
- //#endregion
34
- export { findRemoteFK as n, resolveRelationTargetTable as r, findFKForRelation as t };
File without changes
File without changes