@baseplate-dev/plugin-auth 1.0.1 → 1.0.2

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 (117) hide show
  1. package/dist/auth/core/common.js +2 -2
  2. package/dist/auth/core/common.js.map +1 -1
  3. package/dist/auth/core/components/auth-definition-editor.d.ts.map +1 -1
  4. package/dist/auth/core/components/auth-definition-editor.js +3 -2
  5. package/dist/auth/core/components/auth-definition-editor.js.map +1 -1
  6. package/dist/auth/core/schema/plugin-definition.d.ts +22 -12
  7. package/dist/auth/core/schema/plugin-definition.d.ts.map +1 -1
  8. package/dist/auth/core/schema/plugin-definition.js +10 -10
  9. package/dist/auth/core/schema/plugin-definition.js.map +1 -1
  10. package/dist/auth0/core/common.js +2 -2
  11. package/dist/auth0/core/common.js.map +1 -1
  12. package/dist/auth0/core/components/auth-definition-editor.d.ts.map +1 -1
  13. package/dist/auth0/core/components/auth-definition-editor.js +3 -2
  14. package/dist/auth0/core/components/auth-definition-editor.js.map +1 -1
  15. package/dist/auth0/core/components/role-dialog.d.ts.map +1 -1
  16. package/dist/auth0/core/components/role-dialog.js +3 -1
  17. package/dist/auth0/core/components/role-dialog.js.map +1 -1
  18. package/dist/auth0/core/node.d.ts.map +1 -1
  19. package/dist/auth0/core/node.js +0 -2
  20. package/dist/auth0/core/node.js.map +1 -1
  21. package/dist/auth0/core/schema/plugin-definition.d.ts +19 -9
  22. package/dist/auth0/core/schema/plugin-definition.d.ts.map +1 -1
  23. package/dist/auth0/core/schema/plugin-definition.js +7 -7
  24. package/dist/auth0/core/schema/plugin-definition.js.map +1 -1
  25. package/dist/auth0/generators/fastify/auth0-module/generated/index.d.ts +43 -0
  26. package/dist/auth0/generators/fastify/auth0-module/generated/index.d.ts.map +1 -1
  27. package/dist/auth0/generators/fastify/auth0-module/generated/index.js +2 -0
  28. package/dist/auth0/generators/fastify/auth0-module/generated/index.js.map +1 -1
  29. package/dist/auth0/generators/fastify/auth0-module/generated/template-renderers.d.ts +55 -0
  30. package/dist/auth0/generators/fastify/auth0-module/generated/template-renderers.d.ts.map +1 -0
  31. package/dist/auth0/generators/fastify/auth0-module/generated/template-renderers.js +52 -0
  32. package/dist/auth0/generators/fastify/auth0-module/generated/template-renderers.js.map +1 -0
  33. package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.d.ts +0 -1
  34. package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.d.ts.map +1 -1
  35. package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.js +2 -12
  36. package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.js.map +1 -1
  37. package/dist/auth0/generators/react/auth0-callback/generated/index.d.ts +150 -0
  38. package/dist/auth0/generators/react/auth0-callback/generated/index.d.ts.map +1 -1
  39. package/dist/auth0/generators/react/auth0-callback/generated/index.js +2 -0
  40. package/dist/auth0/generators/react/auth0-callback/generated/index.js.map +1 -1
  41. package/dist/auth0/generators/react/auth0-callback/generated/template-paths.js +2 -2
  42. package/dist/auth0/generators/react/auth0-callback/generated/template-paths.js.map +1 -1
  43. package/dist/auth0/generators/react/auth0-callback/generated/template-renderers.d.ts +162 -0
  44. package/dist/auth0/generators/react/auth0-callback/generated/template-renderers.d.ts.map +1 -0
  45. package/dist/auth0/generators/react/auth0-callback/generated/template-renderers.js +54 -0
  46. package/dist/auth0/generators/react/auth0-callback/generated/template-renderers.js.map +1 -0
  47. package/dist/auth0/generators/react/auth0-callback/generated/typed-templates.js +2 -2
  48. package/dist/auth0/generators/react/auth0-callback/generated/typed-templates.js.map +1 -1
  49. package/dist/auth0/generators/react/auth0-callback/templates/routes/{auth0-callback.page.tsx → auth0-callback.tsx} +6 -4
  50. package/dist/auth0/generators/react/auth0-callback/templates/routes/{signup.page.tsx → signup.tsx} +10 -10
  51. package/dist/auth0/generators/react/auth0-components/generated/index.d.ts +136 -0
  52. package/dist/auth0/generators/react/auth0-components/generated/index.d.ts.map +1 -1
  53. package/dist/auth0/generators/react/auth0-components/generated/index.js +2 -0
  54. package/dist/auth0/generators/react/auth0-components/generated/index.js.map +1 -1
  55. package/dist/auth0/generators/react/auth0-components/generated/template-renderers.d.ts +145 -0
  56. package/dist/auth0/generators/react/auth0-components/generated/template-renderers.d.ts.map +1 -0
  57. package/dist/auth0/generators/react/auth0-components/generated/template-renderers.js +39 -0
  58. package/dist/auth0/generators/react/auth0-components/generated/template-renderers.js.map +1 -0
  59. package/dist/auth0/generators/react/auth0-hooks/generated/index.d.ts +17 -0
  60. package/dist/auth0/generators/react/auth0-hooks/generated/index.d.ts.map +1 -1
  61. package/dist/auth0/generators/react/auth0-hooks/generated/index.js +2 -0
  62. package/dist/auth0/generators/react/auth0-hooks/generated/index.js.map +1 -1
  63. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.d.ts +26 -0
  64. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.d.ts.map +1 -0
  65. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.js +39 -0
  66. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.js.map +1 -0
  67. package/dist/roles/schema.d.ts +29 -10
  68. package/dist/roles/schema.d.ts.map +1 -1
  69. package/dist/roles/schema.js +7 -6
  70. package/dist/roles/schema.js.map +1 -1
  71. package/dist/web/assets/{__federation_expose_auth0CoreCommon-BE50qa2_.js → __federation_expose_auth0CoreCommon-BYomLcgs.js} +4 -4
  72. package/dist/web/assets/__federation_expose_auth0CoreCommon-BYomLcgs.js.map +1 -0
  73. package/dist/web/assets/{__federation_expose_auth0CoreWeb-AdDVCP7O.js → __federation_expose_auth0CoreWeb-T5lCcgD1.js} +14 -8
  74. package/dist/web/assets/__federation_expose_auth0CoreWeb-T5lCcgD1.js.map +1 -0
  75. package/dist/web/assets/{__federation_expose_authCoreCommon-DKyLSPCa.js → __federation_expose_authCoreCommon-CvirZ1-l.js} +4 -4
  76. package/dist/web/assets/__federation_expose_authCoreCommon-CvirZ1-l.js.map +1 -0
  77. package/dist/web/assets/{__federation_expose_authCoreWeb-CfCyOvUk.js → __federation_expose_authCoreWeb-BXQrtVzN.js} +10 -7
  78. package/dist/web/assets/__federation_expose_authCoreWeb-BXQrtVzN.js.map +1 -0
  79. package/dist/web/assets/{__federation_fn_import-CxP86CUK.js → __federation_fn_import-5oUmvVro.js} +2 -2
  80. package/dist/web/assets/{__federation_fn_import-CxP86CUK.js.map → __federation_fn_import-5oUmvVro.js.map} +1 -1
  81. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/{web-BFCvL5ku.js → web-DURp5OH4.js} +12 -12
  82. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-DURp5OH4.js.map +1 -0
  83. package/dist/web/assets/__federation_shared_@baseplate-dev/{project-builder-lib-BAwM_-SS.js → project-builder-lib-SOC0hDo0.js} +572 -193
  84. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-SOC0hDo0.js.map +1 -0
  85. package/dist/web/assets/__federation_shared_@baseplate-dev/{ui-components-C3uzqK6u.js → ui-components-BIPS02bW.js} +5 -5
  86. package/dist/web/assets/__federation_shared_@baseplate-dev/{ui-components-C3uzqK6u.js.map → ui-components-BIPS02bW.js.map} +1 -1
  87. package/dist/web/assets/{index-scyXBD_d.js → index-BAu6L5Vh.js} +2 -2
  88. package/dist/web/assets/{index-scyXBD_d.js.map → index-BAu6L5Vh.js.map} +1 -1
  89. package/dist/web/assets/{index.esm-DIgRm3lq.js → index.esm-C_MMkPsN.js} +2 -2
  90. package/dist/web/assets/{index.esm-DIgRm3lq.js.map → index.esm-C_MMkPsN.js.map} +1 -1
  91. package/dist/web/assets/{model-merger-gxuB007n.js → model-merger-qTOhcMVY.js} +115 -538
  92. package/dist/web/assets/model-merger-qTOhcMVY.js.map +1 -0
  93. package/dist/web/assets/plugin-definition-7hIqggth.js +36 -0
  94. package/dist/web/assets/plugin-definition-7hIqggth.js.map +1 -0
  95. package/dist/web/assets/plugin-definition-BHJF50Kq.js +24 -0
  96. package/dist/web/assets/plugin-definition-BHJF50Kq.js.map +1 -0
  97. package/dist/web/assets/{react-CAuz_DuX.js → react-8Ha9uuy8.js} +2 -2
  98. package/dist/web/assets/{react-CAuz_DuX.js.map → react-8Ha9uuy8.js.map} +1 -1
  99. package/dist/web/assets/remoteEntry.js +4 -4
  100. package/dist/web/assets/schema-BdX0t_km.js +72 -0
  101. package/dist/web/assets/schema-BdX0t_km.js.map +1 -0
  102. package/dist/web/assets/{styles-BpKIyKWd.js → styles-3Wg6h_d_.js} +2 -2
  103. package/dist/web/assets/{styles-BpKIyKWd.js.map → styles-3Wg6h_d_.js.map} +1 -1
  104. package/package.json +10 -10
  105. package/dist/web/assets/__federation_expose_auth0CoreCommon-BE50qa2_.js.map +0 -1
  106. package/dist/web/assets/__federation_expose_auth0CoreWeb-AdDVCP7O.js.map +0 -1
  107. package/dist/web/assets/__federation_expose_authCoreCommon-DKyLSPCa.js.map +0 -1
  108. package/dist/web/assets/__federation_expose_authCoreWeb-CfCyOvUk.js.map +0 -1
  109. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-BFCvL5ku.js.map +0 -1
  110. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-BAwM_-SS.js.map +0 -1
  111. package/dist/web/assets/model-merger-gxuB007n.js.map +0 -1
  112. package/dist/web/assets/plugin-definition-Bgi_XH0-.js +0 -22
  113. package/dist/web/assets/plugin-definition-Bgi_XH0-.js.map +0 -1
  114. package/dist/web/assets/plugin-definition-EtIvYJxn.js +0 -34
  115. package/dist/web/assets/plugin-definition-EtIvYJxn.js.map +0 -1
  116. package/dist/web/assets/schema-BAfRBwYE.js +0 -67
  117. package/dist/web/assets/schema-BAfRBwYE.js.map +0 -1
@@ -1,6 +1,6 @@
1
- import { c as createPluginSpec, i as isEqual, m as mapValues, a as createEntityType, z as zodPluginSymbol, Z as ZodRefWrapper, g as get$1, s as set$1, C as CASE_VALIDATORS, d as definitionSchema, b as zRef, e as modelForeignRelationEntityType, f as modelLocalRelationEntityType, h as modelScalarFieldEntityType, j as zEnt, k as modelTransformerEntityType, l as createDefinitionEntityNameResolver, n as modelEntityType, o as modelEnumValueEntityType, p as featureEntityType, q as modelEnumEntityType, r as zRefBuilder, t as zRefId, u as modelUniqueConstraintEntityType, v as createFeaturesSchema, M as ModelUtils, w as zPluginWrapper, x as omit, y as cloneDeep } from '../model-merger-gxuB007n.js';
2
- export { S as DefinitionDiffArrayIncludesField, Q as DefinitionDiffKeyedArrayField, R as DefinitionDiffReplacementField, G as DefinitionEntityType, F as FeatureUtils, A as ZodPluginWrapper, E as ZodRef, D as ZodRefBuilder, V as applyDefinitionDiff, N as applyModelMergerDiff, O as applyModelMergerResultInPlace, P as createAndApplyModelMergerResults, U as createDefinitionDiff, T as createDefinitionDiffConfig, I as createFeatureSchema, B as createInitializedPluginSpec, K as createModelMergerResult, L as createModelMergerResults, H as featureNameSchema, J as modelMergerDefinitionDiffConfig } from '../model-merger-gxuB007n.js';
3
- import { importShared } from '../__federation_fn_import-CxP86CUK.js';
1
+ import { c as createPluginSpec, i as isEqual, m as mapValues, a as createEntityType, C as CASE_VALIDATORS, D as DefinitionReferenceMarker, g as get$1, R as REF_ANNOTATIONS_MARKER_SYMBOL, b as createDefinitionSchemaParserContext, s as set$1, d as definitionSchema, e as modelForeignRelationEntityType, f as modelLocalRelationEntityType, h as modelScalarFieldEntityType, j as modelTransformerEntityType, k as modelEntityType, l as modelEnumValueEntityType, n as featureEntityType, o as modelEnumEntityType, p as modelUniqueConstraintEntityType, q as createFeaturesSchema, M as ModelUtils, r as omit, t as cloneDeep } from '../model-merger-qTOhcMVY.js';
2
+ export { J as DefinitionDiffArrayIncludesField, H as DefinitionDiffKeyedArrayField, I as DefinitionDiffReplacementField, v as DefinitionEntityType, F as FeatureUtils, N as applyDefinitionDiff, B as applyModelMergerDiff, E as applyModelMergerResultInPlace, G as createAndApplyModelMergerResults, L as createDefinitionDiff, K as createDefinitionDiffConfig, x as createFeatureSchema, u as createInitializedPluginSpec, z as createModelMergerResult, A as createModelMergerResults, w as featureNameSchema, y as modelMergerDefinitionDiffConfig } from '../model-merger-qTOhcMVY.js';
3
+ import { importShared } from '../__federation_fn_import-5oUmvVro.js';
4
4
 
5
5
  function createAdminCrudInputCompilerImplementation() {
6
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -536,15 +536,20 @@ function detectCycle(nodes, visited, edges) {
536
536
  visitSet.delete(node);
537
537
  return false;
538
538
  }
539
- // For cycle detection, we need to find nodes that weren't visited
540
- const unvistedNodeIdx = nodes.findIndex((node, idx) => !visited.has(idx));
541
- if (unvistedNodeIdx === -1) {
542
- return [];
539
+ // For cycle detection, we need to try all unvisited nodes
540
+ for (let i = 0; i < nodes.length; i++) {
541
+ if (!visited.has(i)) {
542
+ // Reset path and visitSet for each starting node
543
+ path.length = 0;
544
+ visitSet.clear();
545
+ const cycleFound = dfs(i);
546
+ if (cycleFound) {
547
+ // Convert path indices to actual nodes
548
+ return path.map((idx) => nodes[idx]);
549
+ }
550
+ }
543
551
  }
544
- // Start DFS from any unvisited node
545
- dfs(unvistedNodeIdx);
546
- // Convert path indices to actual nodes
547
- return path.map((idx) => nodes[idx]);
552
+ return [];
548
553
  }
549
554
  /**
550
555
  * Default comparison function for stable topological sort
@@ -1473,11 +1478,11 @@ function createPluginConfigImplementation() {
1473
1478
  const schemas = new Map();
1474
1479
  const migrationsMap = new Map();
1475
1480
  return {
1476
- registerSchema(pluginKey, schema) {
1481
+ registerSchemaCreator(pluginKey, schemaCreator) {
1477
1482
  if (schemas.has(pluginKey)) {
1478
1483
  throw new Error(`Schema for plugin ${pluginKey} is already registered`);
1479
1484
  }
1480
- schemas.set(pluginKey, schema);
1485
+ schemas.set(pluginKey, schemaCreator);
1481
1486
  },
1482
1487
  registerMigrations(pluginKey, migrations) {
1483
1488
  if (migrationsMap.has(pluginKey)) {
@@ -1486,7 +1491,7 @@ function createPluginConfigImplementation() {
1486
1491
  const sortedMigrations = sortAndValidateMigrations(migrations);
1487
1492
  migrationsMap.set(pluginKey, sortedMigrations);
1488
1493
  },
1489
- getSchema(pluginKey) {
1494
+ getSchemaCreator(pluginKey) {
1490
1495
  return schemas.get(pluginKey);
1491
1496
  },
1492
1497
  getMigrations(pluginKey) {
@@ -1540,31 +1545,6 @@ function runPluginMigrations(projectDefinition, pluginImplementationStore) {
1540
1545
  });
1541
1546
  }
1542
1547
 
1543
- const {ZodType} = await importShared('zod');
1544
- class ZodWithPlugins extends ZodType {
1545
- _parse(input) {
1546
- const context = input.parent.common;
1547
- // run builder
1548
- const zodPluginContext = context[zodPluginSymbol];
1549
- if (!zodPluginContext) {
1550
- throw new Error(`Spec must be run within a Zod plugin context`);
1551
- }
1552
- const innerType = this._def.getter(zodPluginContext.pluginStore, input.data);
1553
- return innerType._parse(input);
1554
- }
1555
- }
1556
- Object.defineProperty(ZodWithPlugins, "create", {
1557
- enumerable: true,
1558
- configurable: true,
1559
- writable: true,
1560
- value: (getter) => new ZodWithPlugins({
1561
- getter,
1562
- })
1563
- });
1564
- function zWithPlugins(getter) {
1565
- return ZodWithPlugins.create(getter);
1566
- }
1567
-
1568
1548
  /**
1569
1549
  * Spec for adding config component for plugin
1570
1550
  */
@@ -2270,6 +2250,349 @@ const AppUtils = {
2270
2250
  getBackendRelativePath,
2271
2251
  };
2272
2252
 
2253
+ const authRoleEntityType = createEntityType('role');
2254
+
2255
+ const appEntityType = createEntityType('app');
2256
+ function createAppEntryType(name) {
2257
+ return name;
2258
+ }
2259
+
2260
+ const {z: z$j} = await importShared('zod');
2261
+ const baseAppValidators = {
2262
+ id: z$j.string().default(appEntityType.generateNewId()),
2263
+ name: CASE_VALIDATORS.KEBAB_CASE,
2264
+ type: z$j.string(),
2265
+ packageLocation: z$j
2266
+ .string()
2267
+ .regex(/^(?!.*(?:\/|\.\.)\/)(?!^\.\.$)(?!^\.$)(?:[\w\-.]+\/?)+[\w\-.]*|^$/, {
2268
+ message: 'Invalid package location. Must be a valid subdirectory.',
2269
+ })
2270
+ .optional(),
2271
+ };
2272
+ const baseAppSchema = z$j.object(baseAppValidators);
2273
+
2274
+ /**
2275
+ * Strips the DefinitionReferenceMarker from the value recursively.
2276
+ * @param value - The value to strip the DefinitionReferenceMarker from.
2277
+ * @returns The value without the DefinitionReferenceMarker.
2278
+ */
2279
+ function stripRefMarkers(value) {
2280
+ if (value instanceof DefinitionReferenceMarker) {
2281
+ return value.value;
2282
+ }
2283
+ if (Array.isArray(value)) {
2284
+ return value.map(stripRefMarkers);
2285
+ }
2286
+ if (typeof value === 'object' && value !== null) {
2287
+ return Object.fromEntries(Object.entries(value).map(([key, childValue]) => [
2288
+ key,
2289
+ stripRefMarkers(childValue),
2290
+ ]));
2291
+ }
2292
+ return value;
2293
+ }
2294
+
2295
+ /**
2296
+ * Creates a definition entity name resolver.
2297
+ * @param entityNameResolver - The entity name resolver.
2298
+ * @returns The definition entity name resolver.
2299
+ */
2300
+ function createDefinitionEntityNameResolver(entityNameResolver) {
2301
+ return entityNameResolver;
2302
+ }
2303
+ /**
2304
+ * DefinitionRefBuilder is responsible for constructing reference paths, and registering
2305
+ * references and entities as defined in a Zod schema.
2306
+ *
2307
+ * The builder uses a prefix (usually the current parsing path) and context (a
2308
+ * shared map for resolving relative references) to build complete reference paths.
2309
+ *
2310
+ * @template TInput - The type of the input data being parsed.
2311
+ */
2312
+ class DefinitionRefBuilder {
2313
+ /**
2314
+ * Creates a new builder instance.
2315
+ * @param pathPrefix - The starting path for all references.
2316
+ * @param context - Shared context including a path map and deserialize flag.
2317
+ * @param data - The data being parsed.
2318
+ */
2319
+ constructor(pathPrefix, context, data) {
2320
+ Object.defineProperty(this, "references", {
2321
+ enumerable: true,
2322
+ configurable: true,
2323
+ writable: true,
2324
+ value: void 0
2325
+ });
2326
+ Object.defineProperty(this, "entitiesWithNameResolver", {
2327
+ enumerable: true,
2328
+ configurable: true,
2329
+ writable: true,
2330
+ value: void 0
2331
+ });
2332
+ Object.defineProperty(this, "pathPrefix", {
2333
+ enumerable: true,
2334
+ configurable: true,
2335
+ writable: true,
2336
+ value: void 0
2337
+ });
2338
+ Object.defineProperty(this, "context", {
2339
+ enumerable: true,
2340
+ configurable: true,
2341
+ writable: true,
2342
+ value: void 0
2343
+ });
2344
+ Object.defineProperty(this, "pathMap", {
2345
+ enumerable: true,
2346
+ configurable: true,
2347
+ writable: true,
2348
+ value: void 0
2349
+ });
2350
+ Object.defineProperty(this, "data", {
2351
+ enumerable: true,
2352
+ configurable: true,
2353
+ writable: true,
2354
+ value: void 0
2355
+ });
2356
+ this.references = [];
2357
+ this.entitiesWithNameResolver = [];
2358
+ this.pathPrefix = pathPrefix;
2359
+ this.context = context;
2360
+ this.pathMap = new Map();
2361
+ this.data = data;
2362
+ }
2363
+ /**
2364
+ * Converts a dot-separated string path into an array of keys.
2365
+ * @param path - A string (e.g. "a.b.0.c") representing the path.
2366
+ * @returns An array of keys (numbers for numeric strings, otherwise strings).
2367
+ */
2368
+ _constructPathWithoutPrefix(path) {
2369
+ if (!path)
2370
+ return [];
2371
+ const pathComponents = path
2372
+ .split('.')
2373
+ .map((key) => (/^[0-9]+$/.test(key) ? Number.parseInt(key, 10) : key));
2374
+ return pathComponents;
2375
+ }
2376
+ /**
2377
+ * Prepends the builder's path prefix to the provided path.
2378
+ * @param path - The dot-separated path string.
2379
+ * @returns The complete reference path as an array.
2380
+ */
2381
+ _constructPath(path) {
2382
+ if (!path)
2383
+ return this.pathPrefix;
2384
+ return [...this.pathPrefix, ...this._constructPathWithoutPrefix(path)];
2385
+ }
2386
+ /**
2387
+ * Constructs a reference path that may be defined directly as a string or indirectly
2388
+ * via a context object. If a context object is provided, the function looks up the
2389
+ * actual path from the builder's context.
2390
+ *
2391
+ * @param path - Either a dot-separated string path or an object with a context key.
2392
+ * @param expectedEntityType - The entity type expected for this context.
2393
+ * @returns The resolved reference path.
2394
+ * @throws If the context cannot be found or its type does not match.
2395
+ */
2396
+ _constructPathWithContext(path, expectedEntityType) {
2397
+ if (typeof path === 'string') {
2398
+ return this._constructPath(path);
2399
+ }
2400
+ // Lookup the context for the given key.
2401
+ const pathContext = this.context.pathMap.get(path.context);
2402
+ if (!pathContext) {
2403
+ throw new Error(`Could not find context for ${path.context} from ${this.pathPrefix.join('.')}`);
2404
+ }
2405
+ if (pathContext.type !== expectedEntityType) {
2406
+ throw new Error(`Attempted to retrieve context for ${path.context} from ${this.pathPrefix.join('.')} expecting ${expectedEntityType.name}, but found ${pathContext.type.name}`);
2407
+ }
2408
+ return pathContext.path;
2409
+ }
2410
+ /**
2411
+ * Registers a reference based on the provided input definition.
2412
+ *
2413
+ * Flow:
2414
+ * 1. Validate that the parent path is provided if required (and vice versa).
2415
+ * 2. Compute the reference path; if the path is empty, use the entire data.
2416
+ * 3. If the referenced value is null or undefined, skip adding the reference.
2417
+ * 4. Otherwise, add the reference and, if requested, register its context.
2418
+ *
2419
+ * @param reference - The reference definition.
2420
+ * @throws If parent path usage is incorrect.
2421
+ */
2422
+ addReference(reference) {
2423
+ if (!reference.type.parentType && reference.parentPath) {
2424
+ throw new Error(`Parent path does nothing since reference does not have parent`);
2425
+ }
2426
+ if (reference.type.parentType && !reference.parentPath) {
2427
+ throw new Error(`Parent path required if reference type has parent type`);
2428
+ }
2429
+ // Compute the path without prefix once.
2430
+ const refPathWithoutPrefix = this._constructPathWithoutPrefix(reference.path);
2431
+ // If the path is empty, use the entire data; otherwise, retrieve the value.
2432
+ const refValue = refPathWithoutPrefix.length === 0
2433
+ ? this.data
2434
+ : get$1(this.data, refPathWithoutPrefix);
2435
+ if (refValue === undefined || refValue === null)
2436
+ return;
2437
+ const fullPath = this._constructPath(reference.path);
2438
+ this.references.push({
2439
+ type: reference.type,
2440
+ path: fullPath,
2441
+ parentPath: reference.parentPath &&
2442
+ reference.type.parentType &&
2443
+ this._constructPathWithContext(reference.parentPath, reference.type.parentType),
2444
+ onDelete: reference.onDelete,
2445
+ });
2446
+ // Optionally, add this path to the shared context.
2447
+ if (reference.addContext) {
2448
+ this._addPathToContext(fullPath, reference.type, reference.addContext);
2449
+ }
2450
+ }
2451
+ /**
2452
+ * Registers an entity based on the provided definition.
2453
+ *
2454
+ * Flow:
2455
+ * 1. Validate that not both a name and a name reference path are provided.
2456
+ * 2. Compute the full entity path.
2457
+ * 3. Resolve the entity ID:
2458
+ * - Use the provided idPath if available; otherwise, default to appending 'id'
2459
+ * to the entity path.
2460
+ * - If no id is found, generate a new one.
2461
+ * 4. Resolve the entity name:
2462
+ * - Use the provided resolveName if available; otherwise, default to using the
2463
+ * name path.
2464
+ * 5. Register the entity in either the direct entities list or the name-ref list.
2465
+ * 6. Optionally, add the entity’s id path to the shared context.
2466
+ *
2467
+ * @param entity - The entity definition.
2468
+ * @throws If both name and nameRefPath are provided or if no name is resolved.
2469
+ */
2470
+ addEntity(entity) {
2471
+ // Build the full path for the entity.
2472
+ const path = this._constructPath(entity.path);
2473
+ // Resolve the id path: if provided use it; otherwise, assume the id is at "entity.path.id"
2474
+ const idPath = entity.idPath
2475
+ ? this._constructPathWithoutPrefix(entity.idPath)
2476
+ : [...this._constructPathWithoutPrefix(entity.path), 'id'];
2477
+ const id = get$1(this.data, idPath);
2478
+ if (!id) {
2479
+ throw new Error(`No id found for entity ${entity.type.name}`);
2480
+ }
2481
+ if (!entity.type.isId(id)) {
2482
+ throw new Error(`Invalid id: ${id} for entity ${entity.type.name}`);
2483
+ }
2484
+ // Resolve the name: if getNameResolver is provided, use it to build the name resolver; otherwise,
2485
+ // use the default name resolver.
2486
+ const getNameResolver = entity.getNameResolver ?? ((value) => get$1(value, 'name'));
2487
+ const nameResolver = getNameResolver(stripRefMarkers(this.data));
2488
+ // Base entity definition shared between regular entities and those with a name reference.
2489
+ const entityBase = {
2490
+ id,
2491
+ type: entity.type,
2492
+ path,
2493
+ idPath: [...this.pathPrefix, ...idPath],
2494
+ parentPath: entity.parentPath &&
2495
+ entity.type.parentType &&
2496
+ this._constructPathWithContext(entity.parentPath, entity.type.parentType),
2497
+ };
2498
+ this.entitiesWithNameResolver.push({
2499
+ ...entityBase,
2500
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- needed to allow more specific generic typed to be put in here
2501
+ nameResolver: typeof nameResolver === 'string'
2502
+ ? { resolveName: () => nameResolver }
2503
+ : nameResolver,
2504
+ });
2505
+ // Optionally add the id path to the context.
2506
+ if (entity.addContext) {
2507
+ this._addPathToContext([...this.pathPrefix, ...idPath], entity.type, entity.addContext);
2508
+ }
2509
+ }
2510
+ /**
2511
+ * Registers a given path into the builder's context map.
2512
+ * @param path - The full reference path.
2513
+ * @param type - The entity type associated with the path.
2514
+ * @param context - A unique key to identify this context.
2515
+ * @throws If the context key is already registered.
2516
+ */
2517
+ _addPathToContext(path, type, context) {
2518
+ // For now, allow overriding contexts to maintain compatibility
2519
+ this.pathMap.set(context, { path, type });
2520
+ // Also register in the shared context for other builders to access
2521
+ this.context.pathMap.set(context, { path, type });
2522
+ }
2523
+ /**
2524
+ * Convenience method that builds a full path from a dot-separated string and
2525
+ * adds it to the context.
2526
+ * @param path - The dot-separated string path.
2527
+ * @param type - The entity type.
2528
+ * @param context - The context key.
2529
+ */
2530
+ addPathToContext(path, type, context) {
2531
+ this._addPathToContext(this._constructPath(path), type, context);
2532
+ }
2533
+ }
2534
+
2535
+ function extractDefinitionRefsRecursive(value, context, path) {
2536
+ const builder = new DefinitionRefBuilder(path, context.context, value);
2537
+ if (value instanceof DefinitionReferenceMarker) {
2538
+ builder.addReference(value.reference);
2539
+ context.references.push(...builder.references);
2540
+ context.entitiesWithNameResolver.push(...builder.entitiesWithNameResolver);
2541
+ return value.value;
2542
+ }
2543
+ if (typeof value === 'object' &&
2544
+ value !== null &&
2545
+ REF_ANNOTATIONS_MARKER_SYMBOL in value) {
2546
+ const annotations = value[REF_ANNOTATIONS_MARKER_SYMBOL];
2547
+ for (const entity of annotations.entities) {
2548
+ builder.addEntity(entity);
2549
+ }
2550
+ for (const reference of annotations.references) {
2551
+ builder.addReference(reference);
2552
+ }
2553
+ for (const pathInfo of annotations.contextPaths) {
2554
+ builder.addPathToContext(pathInfo.path, pathInfo.type, pathInfo.context);
2555
+ }
2556
+ context.references.push(...builder.references);
2557
+ context.entitiesWithNameResolver.push(...builder.entitiesWithNameResolver);
2558
+ // Remove the marker symbol and process the clean object
2559
+ const { [REF_ANNOTATIONS_MARKER_SYMBOL]: _, ...cleanValue } = value;
2560
+ // Process the clean object recursively
2561
+ return Object.fromEntries(Object.entries(cleanValue).map(([key, childValue]) => [
2562
+ key,
2563
+ extractDefinitionRefsRecursive(childValue, context, [...path, key]),
2564
+ ]));
2565
+ }
2566
+ // Run recursively for arrays first (arrays are also objects)
2567
+ if (Array.isArray(value)) {
2568
+ return value.map((element, i) => extractDefinitionRefsRecursive(element, context, [...path, i]));
2569
+ }
2570
+ // Run recursively for regular objects
2571
+ if (typeof value === 'object' && value !== null) {
2572
+ return Object.fromEntries(Object.entries(value).map(([key, childValue]) => [
2573
+ key,
2574
+ extractDefinitionRefsRecursive(childValue, context, [...path, key]),
2575
+ ]));
2576
+ }
2577
+ // Return primitive values as-is
2578
+ return value;
2579
+ }
2580
+ function extractDefinitionRefs(value) {
2581
+ const refContext = {
2582
+ context: {
2583
+ pathMap: new Map(),
2584
+ },
2585
+ references: [],
2586
+ entitiesWithNameResolver: [],
2587
+ };
2588
+ const cleanData = extractDefinitionRefsRecursive(value, refContext, []);
2589
+ return {
2590
+ data: cleanData,
2591
+ references: refContext.references,
2592
+ entitiesWithNameResolver: refContext.entitiesWithNameResolver,
2593
+ };
2594
+ }
2595
+
2273
2596
  /**
2274
2597
  * Resolves entity names in a ZodRefPayload.
2275
2598
  *
@@ -2329,19 +2652,47 @@ function resolveZodRefPayloadNames(payload, { skipReferenceNameResolution = fals
2329
2652
  *
2330
2653
  * @returns The parsed data.
2331
2654
  */
2332
- function parseSchemaWithReferences(schema, input, options) {
2333
- const wrapper = ZodRefWrapper.create(schema);
2334
- return resolveZodRefPayloadNames(wrapper.parse(input), options);
2655
+ function parseSchemaWithTransformedReferences(schemaCreator, input, schemaCreatorOptions, options) {
2656
+ const schemaContext = createDefinitionSchemaParserContext({
2657
+ ...schemaCreatorOptions,
2658
+ transformReferences: true,
2659
+ });
2660
+ const schema = schemaCreator(schemaContext);
2661
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- using the type T which can be any zod schema
2662
+ const value = schema.parse(input);
2663
+ const refPayload = extractDefinitionRefs(value);
2664
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- using the type T which can be any zod schema
2665
+ return resolveZodRefPayloadNames(refPayload, options);
2335
2666
  }
2336
2667
 
2337
2668
  function referenceToNameParentId(name, parentId) {
2338
2669
  return JSON.stringify({ name, parentId });
2339
2670
  }
2340
- function deserializeSchemaWithReferences(schema, input) {
2341
- const payload = parseSchemaWithReferences(schema, input, {
2671
+ /**
2672
+ * Deserialize a schema with references using the new transform-based approach.
2673
+ * This function converts human-readable names back to entity IDs.
2674
+ *
2675
+ * @template T - The schema creator type
2676
+ * @param schemaCreator - The schema creator function
2677
+ * @param input - The input data with names instead of IDs
2678
+ * @param options - Options for the schema creator (excluding transformReferences)
2679
+ * @returns The resolved payload with IDs instead of names
2680
+ */
2681
+ function deserializeSchemaWithTransformedReferences(schemaCreator, input, options) {
2682
+ const payload = parseSchemaWithTransformedReferences(schemaCreator, input, options, {
2342
2683
  skipReferenceNameResolution: true,
2343
2684
  });
2344
- // resolve all references
2685
+ // Use the same resolution logic as the original function
2686
+ return resolveReferencesToIds(payload);
2687
+ }
2688
+ /**
2689
+ * Internal function to resolve entity names to IDs in the payload.
2690
+ * This is shared logic between the old and new approaches.
2691
+ *
2692
+ * @param payload - The parsed payload with entities and references
2693
+ * @returns The payload with references resolved to IDs
2694
+ */
2695
+ function resolveReferencesToIds(payload) {
2345
2696
  const { references, entities, data } = payload;
2346
2697
  // check we don't have more entities than IDs
2347
2698
  const entitiesById = groupBy(entities, (entity) => entity.id);
@@ -2403,13 +2754,13 @@ const DELETED_SENTINEL_ID = 'deleted-sentinel-id';
2403
2754
  /**
2404
2755
  * Fixes any reference deletions by performing the appropriate action for the reference
2405
2756
  */
2406
- function fixRefDeletions(schema, value) {
2757
+ function fixRefDeletions(schemaCreator, value, schemaCreatorOptions) {
2407
2758
  const issues = [];
2408
2759
  // find all references that do not have a corresponding entity
2409
2760
  let iterations;
2410
2761
  let valueToEdit = value;
2411
2762
  for (iterations = 0; iterations < 100; iterations++) {
2412
- const parseResult = parseSchemaWithReferences(schema, valueToEdit, {
2763
+ const parseResult = parseSchemaWithTransformedReferences(schemaCreator, valueToEdit, schemaCreatorOptions, {
2413
2764
  allowInvalidReferences: true,
2414
2765
  });
2415
2766
  const { references, entities } = parseResult;
@@ -2452,8 +2803,16 @@ function fixRefDeletions(schema, value) {
2452
2803
  for (const ref of referencesMissingEntity) {
2453
2804
  const id = get$1(valueToEdit, ref.path);
2454
2805
  switch (ref.onDelete) {
2455
- case 'SET_NULL': {
2456
- set$1(valueToEdit, ref.path, null);
2806
+ case 'SET_UNDEFINED': {
2807
+ // Check if reference is inside an array
2808
+ if (ref.path.length > 0) {
2809
+ const parentPath = ref.path.slice(0, -1);
2810
+ const parent = get$1(valueToEdit, parentPath);
2811
+ if (Array.isArray(parent)) {
2812
+ throw new TypeError(`SET_UNDEFINED cannot be used for references inside arrays at path ${ref.path.join('.')}. Use DELETE instead to remove the array element.`);
2813
+ }
2814
+ }
2815
+ set$1(valueToEdit, ref.path, undefined);
2457
2816
  break;
2458
2817
  }
2459
2818
  case 'RESTRICT': {
@@ -2508,32 +2867,12 @@ function serializeSchemaFromRefPayload(payload) {
2508
2867
  }
2509
2868
  })(data);
2510
2869
  }
2511
- function serializeSchema(schema, value) {
2512
- const payload = parseSchemaWithReferences(schema, value);
2870
+ function serializeSchema(schemaCreator, value, schemaCreatorOptions) {
2871
+ const payload = parseSchemaWithTransformedReferences(schemaCreator, value, schemaCreatorOptions);
2872
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- typed as def.InferOutput<T>
2513
2873
  return serializeSchemaFromRefPayload(payload);
2514
2874
  }
2515
2875
 
2516
- const authRoleEntityType = createEntityType('role');
2517
-
2518
- const appEntityType = createEntityType('app');
2519
- function createAppEntryType(name) {
2520
- return name;
2521
- }
2522
-
2523
- const {z: z$j} = await importShared('zod');
2524
- const baseAppValidators = {
2525
- id: z$j.string().default(appEntityType.generateNewId()),
2526
- name: CASE_VALIDATORS.KEBAB_CASE,
2527
- type: z$j.string(),
2528
- packageLocation: z$j
2529
- .string()
2530
- .regex(/^(?!.*(?:\/|\.\.)\/)(?!^\.\.$)(?!^\.$)(?:[\w\-.]+\/?)+[\w\-.]*|^$/, {
2531
- message: 'Invalid package location. Must be a valid subdirectory.',
2532
- })
2533
- .optional(),
2534
- };
2535
- const baseAppSchema = z$j.object(baseAppValidators);
2536
-
2537
2876
  const SCALAR_FIELD_TYPES = [
2538
2877
  'string',
2539
2878
  'uuid',
@@ -2599,30 +2938,30 @@ const VALIDATORS = {
2599
2938
  };
2600
2939
 
2601
2940
  const {z: z$g} = await importShared('zod');
2602
- const roleArray = z$g
2603
- .array(zRef(z$g.string(), {
2941
+ const createRoleArray = definitionSchema((ctx) => z$g
2942
+ .array(ctx.withRef({
2604
2943
  type: authRoleEntityType,
2605
2944
  onDelete: 'DELETE',
2606
2945
  }))
2607
- .optional();
2608
- const createModelGraphqlSchema = definitionSchema(() => z$g.object({
2946
+ .optional());
2947
+ const createModelGraphqlSchema = definitionSchema((ctx) => z$g.object({
2609
2948
  objectType: z$g
2610
2949
  .object({
2611
2950
  enabled: z$g.boolean().default(false),
2612
- fields: z$g.array(zRef(z$g.string(), {
2951
+ fields: z$g.array(ctx.withRef({
2613
2952
  type: modelScalarFieldEntityType,
2614
2953
  onDelete: 'DELETE',
2615
2954
  parentPath: { context: 'model' },
2616
2955
  })),
2617
2956
  localRelations: z$g
2618
- .array(zRef(z$g.string(), {
2957
+ .array(ctx.withRef({
2619
2958
  type: modelLocalRelationEntityType,
2620
2959
  onDelete: 'DELETE',
2621
2960
  parentPath: { context: 'model' },
2622
2961
  }))
2623
2962
  .optional(),
2624
2963
  foreignRelations: z$g
2625
- .array(zRef(z$g.string(), {
2964
+ .array(ctx.withRef({
2626
2965
  type: modelForeignRelationEntityType,
2627
2966
  onDelete: 'DELETE',
2628
2967
  parentPath: { context: 'model' },
@@ -2638,13 +2977,13 @@ const createModelGraphqlSchema = definitionSchema(() => z$g.object({
2638
2977
  get: z$g
2639
2978
  .object({
2640
2979
  enabled: z$g.boolean().optional(),
2641
- roles: roleArray,
2980
+ roles: createRoleArray(ctx),
2642
2981
  })
2643
2982
  .optional(),
2644
2983
  list: z$g
2645
2984
  .object({
2646
2985
  enabled: z$g.boolean().optional(),
2647
- roles: roleArray,
2986
+ roles: createRoleArray(ctx),
2648
2987
  })
2649
2988
  .optional(),
2650
2989
  })
@@ -2663,7 +3002,7 @@ const createModelGraphqlSchema = definitionSchema(() => z$g.object({
2663
3002
  create: z$g
2664
3003
  .object({
2665
3004
  enabled: z$g.boolean().optional(),
2666
- roles: roleArray,
3005
+ roles: createRoleArray(ctx),
2667
3006
  })
2668
3007
  .default({
2669
3008
  enabled: false,
@@ -2672,7 +3011,7 @@ const createModelGraphqlSchema = definitionSchema(() => z$g.object({
2672
3011
  update: z$g
2673
3012
  .object({
2674
3013
  enabled: z$g.boolean().optional(),
2675
- roles: roleArray,
3014
+ roles: createRoleArray(ctx),
2676
3015
  })
2677
3016
  .default({
2678
3017
  enabled: false,
@@ -2681,7 +3020,7 @@ const createModelGraphqlSchema = definitionSchema(() => z$g.object({
2681
3020
  delete: z$g
2682
3021
  .object({
2683
3022
  enabled: z$g.boolean().optional(),
2684
- roles: roleArray,
3023
+ roles: createRoleArray(ctx),
2685
3024
  })
2686
3025
  .default({
2687
3026
  enabled: false,
@@ -2694,18 +3033,16 @@ const createModelGraphqlSchema = definitionSchema(() => z$g.object({
2694
3033
  const {z: z$f} = await importShared('zod');
2695
3034
 
2696
3035
  const baseTransformerFields = {
3036
+ id: z$f.string(),
2697
3037
  type: z$f.string().min(1),
2698
3038
  };
2699
- const baseTransformerSchema = z$f.object({
2700
- id: z$f.string(),
2701
- ...baseTransformerFields,
2702
- });
3039
+ const baseTransformerSchema = z$f.object(baseTransformerFields);
2703
3040
  function createModelTransformerType(payload) {
2704
3041
  return payload;
2705
3042
  }
2706
3043
 
2707
3044
  const {z: z$e} = await importShared('zod');
2708
- const createPasswordTransformerSchema = definitionSchema(() => zEnt(z$e.object({
3045
+ const createPasswordTransformerSchema = definitionSchema((ctx) => ctx.withEnt(z$e.object({
2709
3046
  ...baseTransformerFields,
2710
3047
  type: z$e.literal('password'),
2711
3048
  }), {
@@ -2713,27 +3050,27 @@ const createPasswordTransformerSchema = definitionSchema(() => zEnt(z$e.object({
2713
3050
  parentPath: { context: 'model' },
2714
3051
  getNameResolver: () => 'password',
2715
3052
  }));
2716
- const createEmbeddedRelationTransformerSchema = definitionSchema(() => zEnt(z$e.object({
3053
+ const createEmbeddedRelationTransformerSchema = definitionSchema((ctx) => ctx.withRefBuilder(ctx.withEnt(z$e.object({
2717
3054
  ...baseTransformerFields,
2718
- foreignRelationRef: zRef(z$e.string().min(1), {
3055
+ foreignRelationRef: ctx.withRef({
2719
3056
  type: modelForeignRelationEntityType,
2720
3057
  onDelete: 'DELETE_PARENT',
2721
3058
  parentPath: { context: 'model' },
2722
3059
  }),
2723
3060
  type: z$e.literal('embeddedRelation'),
2724
- embeddedFieldNames: z$e.array(zRef(z$e.string().min(1), {
3061
+ embeddedFieldNames: z$e.array(ctx.withRef({
2725
3062
  type: modelScalarFieldEntityType,
2726
3063
  onDelete: 'RESTRICT',
2727
3064
  parentPath: { context: 'embeddedModel' },
2728
3065
  })),
2729
3066
  embeddedTransformerNames: z$e
2730
- .array(zRef(z$e.string().min(1), {
3067
+ .array(ctx.withRef({
2731
3068
  type: modelTransformerEntityType,
2732
3069
  onDelete: 'RESTRICT',
2733
3070
  parentPath: { context: 'embeddedModel' },
2734
3071
  }))
2735
3072
  .optional(),
2736
- modelRef: zRef(z$e.string().min(1), {
3073
+ modelRef: ctx.withRef({
2737
3074
  type: modelEntityType,
2738
3075
  onDelete: 'RESTRICT',
2739
3076
  }),
@@ -2744,18 +3081,18 @@ const createEmbeddedRelationTransformerSchema = definitionSchema(() => zEnt(z$e.
2744
3081
  idsToResolve: { foreignRelation: entity.foreignRelationRef },
2745
3082
  resolveName: (entityNames) => entityNames.foreignRelation,
2746
3083
  }),
2747
- }).refBuilder((builder) => {
3084
+ }), (builder) => {
2748
3085
  builder.addPathToContext('modelRef', modelEntityType, 'embeddedModel');
2749
3086
  }));
2750
3087
  const BUILT_IN_TRANSFORMERS = [
2751
3088
  createModelTransformerType({
2752
3089
  name: 'password',
2753
- schema: createPasswordTransformerSchema,
3090
+ createSchema: createPasswordTransformerSchema,
2754
3091
  getName: () => 'Password',
2755
3092
  }),
2756
3093
  createModelTransformerType({
2757
3094
  name: 'embeddedRelation',
2758
- schema: createEmbeddedRelationTransformerSchema,
3095
+ createSchema: createEmbeddedRelationTransformerSchema,
2759
3096
  getName: (definitionContainer, definition) => definitionContainer.nameFromId(definition.foreignRelationRef),
2760
3097
  }),
2761
3098
  ];
@@ -2793,16 +3130,22 @@ const modelTransformerSpec = createPluginSpec('core/model-transformer', {
2793
3130
  defaultInitializer: createModelTransformerImplementation,
2794
3131
  });
2795
3132
 
2796
- const createTransformerSchema = definitionSchema((ctx) => zWithPlugins((plugins, data) => {
2797
- const { type } = baseTransformerSchema.parse(data);
2798
- const transformer = plugins
3133
+ const createTransformerSchema = definitionSchema((ctx) => baseTransformerSchema.passthrough().transform((data, parseCtx) => {
3134
+ const { type } = data;
3135
+ const transformer = ctx.plugins
2799
3136
  .getPluginSpec(modelTransformerSpec)
2800
3137
  .getModelTransformer(type);
2801
- return transformer.schema(ctx);
3138
+ return transformer
3139
+ .createSchema(ctx)
3140
+ .and(baseTransformerSchema)
3141
+ .parse(data, {
3142
+ path: parseCtx.path,
3143
+ });
2802
3144
  }));
2803
3145
 
2804
3146
  const {z: z$d} = await importShared('zod');
2805
- const createEnumValueSchema = definitionSchema(() => zEnt(z$d.object({
3147
+ const createEnumValueSchema = definitionSchema((ctx) => ctx.withEnt(z$d.object({
3148
+ id: z$d.string(),
2806
3149
  name: z$d.string().min(1),
2807
3150
  friendlyName: z$d.string().min(1),
2808
3151
  }), {
@@ -2810,25 +3153,28 @@ const createEnumValueSchema = definitionSchema(() => zEnt(z$d.object({
2810
3153
  parentPath: { context: 'enum' },
2811
3154
  }));
2812
3155
  const createEnumBaseSchema = definitionSchema((ctx) => z$d.object({
3156
+ id: z$d.string(),
2813
3157
  name: z$d.string().min(1),
2814
- featureRef: zRef(z$d.string().min(1), {
3158
+ featureRef: ctx.withRef({
2815
3159
  type: featureEntityType,
2816
3160
  onDelete: 'RESTRICT',
2817
3161
  }),
2818
3162
  values: z$d.array(createEnumValueSchema(ctx)),
2819
3163
  isExposed: z$d.boolean(),
2820
3164
  }));
2821
- const createEnumSchema = definitionSchema((ctx) => zEnt(createEnumBaseSchema(ctx), {
3165
+ const createEnumSchema = definitionSchema((ctx) => ctx.withEnt(createEnumBaseSchema(ctx), {
2822
3166
  type: modelEnumEntityType,
2823
3167
  addContext: 'enum',
2824
3168
  }));
2825
3169
 
2826
3170
  const {z: z$c} = await importShared('zod');
2827
- const createModelScalarFieldSchema = definitionSchema(() => zEnt(z$c.object({
3171
+ const createModelScalarFieldSchema = definitionSchema((ctx) => ctx
3172
+ .withEnt(z$c.object({
3173
+ id: z$c.string(),
2828
3174
  name: VALIDATORS.CAMEL_CASE_STRING,
2829
3175
  type: z$c.enum(SCALAR_FIELD_TYPES),
2830
3176
  isOptional: z$c.boolean().default(false),
2831
- options: zRefBuilder(z$c
3177
+ options: ctx.withRefBuilder(z$c
2832
3178
  .object({
2833
3179
  // string options
2834
3180
  default: z$c.string().default(''),
@@ -2838,10 +3184,12 @@ const createModelScalarFieldSchema = definitionSchema(() => zEnt(z$c.object({
2838
3184
  updatedAt: z$c.boolean().optional(),
2839
3185
  defaultToNow: z$c.boolean().optional(),
2840
3186
  // enum options
2841
- enumRef: zRef(z$c.string().optional(), {
3187
+ enumRef: ctx
3188
+ .withRef({
2842
3189
  type: modelEnumEntityType,
2843
3190
  onDelete: 'RESTRICT',
2844
- }),
3191
+ })
3192
+ .optional(),
2845
3193
  defaultEnumValueRef: z$c.string().optional(),
2846
3194
  })
2847
3195
  .transform((val) => ({
@@ -2894,19 +3242,19 @@ const REFERENTIAL_ACTIONS = [
2894
3242
  'SetNull',
2895
3243
  'SetDefault',
2896
3244
  ];
2897
- const createModelRelationFieldSchema = definitionSchema(() => zRefBuilder(z$c.object({
2898
- id: zRefId,
3245
+ const createModelRelationFieldSchema = definitionSchema((ctx) => ctx.withRefBuilder(z$c.object({
3246
+ id: z$c.string(),
2899
3247
  foreignId: z$c
2900
3248
  .string()
2901
3249
  .default(() => modelForeignRelationEntityType.generateNewId()),
2902
3250
  name: VALIDATORS.CAMEL_CASE_STRING,
2903
3251
  references: z$c.array(z$c.object({
2904
- localRef: zRef(z$c.string(), {
3252
+ localRef: ctx.withRef({
2905
3253
  type: modelScalarFieldEntityType,
2906
3254
  onDelete: 'RESTRICT',
2907
3255
  parentPath: { context: 'model' },
2908
3256
  }),
2909
- foreignRef: zRef(z$c.string(), {
3257
+ foreignRef: ctx.withRef({
2910
3258
  type: modelScalarFieldEntityType,
2911
3259
  onDelete: 'RESTRICT',
2912
3260
  parentPath: { context: 'foreignModel' },
@@ -2934,9 +3282,10 @@ const createModelRelationFieldSchema = definitionSchema(() => zRefBuilder(z$c.ob
2934
3282
  parentPath: 'modelRef',
2935
3283
  });
2936
3284
  }));
2937
- const createModelUniqueConstraintSchema = definitionSchema(() => zEnt(z$c.object({
3285
+ const createModelUniqueConstraintSchema = definitionSchema((ctx) => ctx.withEnt(z$c.object({
3286
+ id: z$c.string(),
2938
3287
  fields: z$c.array(z$c.object({
2939
- fieldRef: zRef(z$c.string().min(1), {
3288
+ fieldRef: ctx.withRef({
2940
3289
  type: modelScalarFieldEntityType,
2941
3290
  onDelete: 'RESTRICT',
2942
3291
  parentPath: { context: 'model' },
@@ -2957,14 +3306,14 @@ const createModelServiceSchema = definitionSchema((ctx) => z$c.object({
2957
3306
  .object({
2958
3307
  enabled: z$c.boolean().default(false),
2959
3308
  fields: z$c
2960
- .array(zRef(z$c.string(), {
3309
+ .array(ctx.withRef({
2961
3310
  type: modelScalarFieldEntityType,
2962
3311
  onDelete: 'DELETE',
2963
3312
  parentPath: { context: 'model' },
2964
3313
  }))
2965
3314
  .optional(),
2966
3315
  transformerNames: z$c
2967
- .array(zRef(z$c.string(), {
3316
+ .array(ctx.withRef({
2968
3317
  type: modelTransformerEntityType,
2969
3318
  onDelete: 'DELETE',
2970
3319
  parentPath: { context: 'model' },
@@ -2976,14 +3325,14 @@ const createModelServiceSchema = definitionSchema((ctx) => z$c.object({
2976
3325
  .object({
2977
3326
  enabled: z$c.boolean().default(false),
2978
3327
  fields: z$c
2979
- .array(zRef(z$c.string(), {
3328
+ .array(ctx.withRef({
2980
3329
  type: modelScalarFieldEntityType,
2981
3330
  onDelete: 'DELETE',
2982
3331
  parentPath: { context: 'model' },
2983
3332
  }))
2984
3333
  .optional(),
2985
3334
  transformerNames: z$c
2986
- .array(zRef(z$c.string(), {
3335
+ .array(ctx.withRef({
2987
3336
  type: modelTransformerEntityType,
2988
3337
  onDelete: 'DELETE',
2989
3338
  parentPath: { context: 'model' },
@@ -3001,9 +3350,9 @@ const createModelServiceSchema = definitionSchema((ctx) => z$c.object({
3001
3350
  transformers: z$c.array(createTransformerSchema(ctx)).default([]),
3002
3351
  }));
3003
3352
  const createModelBaseSchema = definitionSchema((ctx) => z$c.object({
3004
- id: zRefId,
3353
+ id: z$c.string(),
3005
3354
  name: VALIDATORS.PASCAL_CASE_STRING,
3006
- featureRef: zRef(z$c.string().min(1), {
3355
+ featureRef: ctx.withRef({
3007
3356
  type: featureEntityType,
3008
3357
  onDelete: 'RESTRICT',
3009
3358
  }),
@@ -3011,7 +3360,7 @@ const createModelBaseSchema = definitionSchema((ctx) => z$c.object({
3011
3360
  fields: z$c.array(createModelScalarFieldSchema(ctx)),
3012
3361
  relations: z$c.array(createModelRelationFieldSchema(ctx)).optional(),
3013
3362
  primaryKeyFieldRefs: z$c
3014
- .array(zRef(z$c.string(), {
3363
+ .array(ctx.withRef({
3015
3364
  type: modelScalarFieldEntityType,
3016
3365
  onDelete: 'RESTRICT',
3017
3366
  parentPath: { context: 'model' },
@@ -3029,7 +3378,7 @@ const createModelBaseSchema = definitionSchema((ctx) => z$c.object({
3029
3378
  }),
3030
3379
  graphql: createModelGraphqlSchema(ctx).optional(),
3031
3380
  }));
3032
- const createModelSchema = definitionSchema((ctx) => zEnt(createModelBaseSchema(ctx), {
3381
+ const createModelSchema = definitionSchema((ctx) => ctx.withEnt(createModelBaseSchema(ctx), {
3033
3382
  type: modelEntityType,
3034
3383
  addContext: 'model',
3035
3384
  }));
@@ -3039,16 +3388,16 @@ const adminSectionEntityType = createEntityType('admin-section', {
3039
3388
  });
3040
3389
 
3041
3390
  const {z: z$b} = await importShared('zod');
3042
- const baseAdminSectionValidators = {
3391
+ const createBaseAdminSectionValidators = definitionSchema((ctx) => z$b.object({
3043
3392
  id: z$b.string().default(adminSectionEntityType.generateNewId()),
3044
3393
  name: z$b.string().min(1),
3045
- featureRef: zRef(z$b.string().min(1), {
3394
+ featureRef: ctx.withRef({
3046
3395
  type: featureEntityType,
3047
3396
  onDelete: 'RESTRICT',
3048
3397
  }),
3049
3398
  icon: z$b.string().optional(),
3050
3399
  type: z$b.string().min(1),
3051
- };
3400
+ }));
3052
3401
 
3053
3402
  const {z: z$a} = await importShared('zod');
3054
3403
  const baseAdminCrudInputSchema = z$a.object({
@@ -3063,10 +3412,10 @@ const adminCrudEmbeddedFormEntityType = createEntityType('admin-crud-embedded-fo
3063
3412
  });
3064
3413
 
3065
3414
  const {z: z$9} = await importShared('zod');
3066
- const createAdminCrudTextInputSchema = definitionSchema(() => z$9.object({
3415
+ const createAdminCrudTextInputSchema = definitionSchema((ctx) => z$9.object({
3067
3416
  type: z$9.literal('text'),
3068
3417
  label: z$9.string().min(1),
3069
- modelFieldRef: zRef(z$9.string(), {
3418
+ modelFieldRef: ctx.withRef({
3070
3419
  type: modelScalarFieldEntityType,
3071
3420
  onDelete: 'RESTRICT',
3072
3421
  parentPath: { context: 'model' },
@@ -3075,12 +3424,12 @@ const createAdminCrudTextInputSchema = definitionSchema(() => z$9.object({
3075
3424
  }));
3076
3425
  const adminCrudTextInputType = createAdminCrudInputType({
3077
3426
  name: 'text',
3078
- schema: createAdminCrudTextInputSchema,
3427
+ createSchema: createAdminCrudTextInputSchema,
3079
3428
  });
3080
- const createAdminCrudForeignInputSchema = definitionSchema(() => z$9.object({
3429
+ const createAdminCrudForeignInputSchema = definitionSchema((ctx) => z$9.object({
3081
3430
  type: z$9.literal('foreign'),
3082
3431
  label: z$9.string().min(1),
3083
- localRelationRef: zRef(z$9.string(), {
3432
+ localRelationRef: ctx.withRef({
3084
3433
  type: modelLocalRelationEntityType,
3085
3434
  onDelete: 'RESTRICT',
3086
3435
  parentPath: { context: 'model' },
@@ -3092,12 +3441,12 @@ const createAdminCrudForeignInputSchema = definitionSchema(() => z$9.object({
3092
3441
  }));
3093
3442
  const adminCrudForeignInputType = createAdminCrudInputType({
3094
3443
  name: 'foreign',
3095
- schema: createAdminCrudForeignInputSchema,
3444
+ createSchema: createAdminCrudForeignInputSchema,
3096
3445
  });
3097
- const createAdminCrudEnumInputSchema = definitionSchema(() => z$9.object({
3446
+ const createAdminCrudEnumInputSchema = definitionSchema((ctx) => z$9.object({
3098
3447
  type: z$9.literal('enum'),
3099
3448
  label: z$9.string().min(1),
3100
- modelFieldRef: zRef(z$9.string(), {
3449
+ modelFieldRef: ctx.withRef({
3101
3450
  type: modelScalarFieldEntityType,
3102
3451
  onDelete: 'RESTRICT',
3103
3452
  parentPath: { context: 'model' },
@@ -3105,17 +3454,17 @@ const createAdminCrudEnumInputSchema = definitionSchema(() => z$9.object({
3105
3454
  }));
3106
3455
  const adminCrudEnumInputType = createAdminCrudInputType({
3107
3456
  name: 'enum',
3108
- schema: createAdminCrudEnumInputSchema,
3457
+ createSchema: createAdminCrudEnumInputSchema,
3109
3458
  });
3110
- const createAdminCrudEmbeddedInputSchema = definitionSchema(() => z$9.object({
3459
+ const createAdminCrudEmbeddedInputSchema = definitionSchema((ctx) => z$9.object({
3111
3460
  type: z$9.literal('embedded'),
3112
3461
  label: z$9.string().min(1),
3113
- modelRelationRef: zRef(z$9.string(), {
3462
+ modelRelationRef: ctx.withRef({
3114
3463
  type: modelForeignRelationEntityType,
3115
3464
  onDelete: 'RESTRICT',
3116
3465
  parentPath: { context: 'model' },
3117
3466
  }),
3118
- embeddedFormRef: zRef(z$9.string(), {
3467
+ embeddedFormRef: ctx.withRef({
3119
3468
  type: adminCrudEmbeddedFormEntityType,
3120
3469
  parentPath: { context: 'admin-section' },
3121
3470
  onDelete: 'RESTRICT',
@@ -3123,17 +3472,17 @@ const createAdminCrudEmbeddedInputSchema = definitionSchema(() => z$9.object({
3123
3472
  }));
3124
3473
  const adminCrudEmbeddedInputType = createAdminCrudInputType({
3125
3474
  name: 'embedded',
3126
- schema: createAdminCrudEmbeddedInputSchema,
3475
+ createSchema: createAdminCrudEmbeddedInputSchema,
3127
3476
  });
3128
- const createAdminCrudEmbeddedLocalInputSchema = definitionSchema(() => z$9.object({
3477
+ const createAdminCrudEmbeddedLocalInputSchema = definitionSchema((ctx) => z$9.object({
3129
3478
  type: z$9.literal('embeddedLocal'),
3130
3479
  label: z$9.string().min(1),
3131
- localRelationRef: zRef(z$9.string(), {
3480
+ localRelationRef: ctx.withRef({
3132
3481
  type: modelLocalRelationEntityType,
3133
3482
  onDelete: 'RESTRICT',
3134
3483
  parentPath: { context: 'model' },
3135
3484
  }),
3136
- embeddedFormRef: zRef(z$9.string(), {
3485
+ embeddedFormRef: ctx.withRef({
3137
3486
  type: adminCrudEmbeddedFormEntityType,
3138
3487
  parentPath: { context: 'admin-section' },
3139
3488
  onDelete: 'RESTRICT',
@@ -3141,7 +3490,7 @@ const createAdminCrudEmbeddedLocalInputSchema = definitionSchema(() => z$9.objec
3141
3490
  }));
3142
3491
  const adminCrudEmbeddedLocalInputType = createAdminCrudInputType({
3143
3492
  name: 'embeddedLocal',
3144
- schema: createAdminCrudEmbeddedLocalInputSchema,
3493
+ createSchema: createAdminCrudEmbeddedLocalInputSchema,
3145
3494
  });
3146
3495
  const createAdminCrudPasswordInputSchema = definitionSchema(() => z$9.object({
3147
3496
  type: z$9.literal('password'),
@@ -3149,7 +3498,7 @@ const createAdminCrudPasswordInputSchema = definitionSchema(() => z$9.object({
3149
3498
  }));
3150
3499
  const adminCrudPasswordInputType = createAdminCrudInputType({
3151
3500
  name: 'password',
3152
- schema: createAdminCrudPasswordInputSchema,
3501
+ createSchema: createAdminCrudPasswordInputSchema,
3153
3502
  });
3154
3503
  const BUILT_IN_ADMIN_CRUD_INPUTS = [
3155
3504
  adminCrudTextInputType,
@@ -3188,19 +3537,24 @@ const adminCrudInputSpec = createPluginSpec('core/admin-crud-input', {
3188
3537
  defaultInitializer: createAdminCrudInputImplementation,
3189
3538
  });
3190
3539
 
3191
- const createAdminCrudInputSchema = definitionSchema((ctx) => zWithPlugins((plugins, data) => {
3192
- const { type } = baseAdminCrudInputSchema.parse(data);
3193
- const input = plugins
3540
+ const createAdminCrudInputSchema = definitionSchema((ctx) => baseAdminCrudInputSchema.passthrough().transform((data, parseCtx) => {
3541
+ const { type } = data;
3542
+ const crudInput = ctx.plugins
3194
3543
  .getPluginSpec(adminCrudInputSpec)
3195
3544
  .getAdminCrudInput(type);
3196
- return input.schema(ctx);
3545
+ return crudInput
3546
+ .createSchema(ctx)
3547
+ .and(baseAdminCrudInputSchema)
3548
+ .parse(data, {
3549
+ path: parseCtx.path,
3550
+ });
3197
3551
  }));
3198
3552
 
3199
3553
  const {z: z$8} = await importShared('zod');
3200
3554
  // Table Columns
3201
- const createAdminCrudForeignDisplaySchema = definitionSchema(() => z$8.object({
3555
+ const createAdminCrudForeignDisplaySchema = definitionSchema((ctx) => z$8.object({
3202
3556
  type: z$8.literal('foreign'),
3203
- localRelationRef: zRef(z$8.string(), {
3557
+ localRelationRef: ctx.withRef({
3204
3558
  type: modelLocalRelationEntityType,
3205
3559
  onDelete: 'RESTRICT',
3206
3560
  parentPath: { context: 'model' },
@@ -3208,9 +3562,9 @@ const createAdminCrudForeignDisplaySchema = definitionSchema(() => z$8.object({
3208
3562
  labelExpression: z$8.string().min(1),
3209
3563
  valueExpression: z$8.string().min(1),
3210
3564
  }));
3211
- const createAdminCrudTextDisplaySchema = definitionSchema(() => z$8.object({
3565
+ const createAdminCrudTextDisplaySchema = definitionSchema((ctx) => z$8.object({
3212
3566
  type: z$8.literal('text'),
3213
- modelFieldRef: zRef(z$8.string(), {
3567
+ modelFieldRef: ctx.withRef({
3214
3568
  type: modelScalarFieldEntityType,
3215
3569
  onDelete: 'RESTRICT',
3216
3570
  parentPath: { context: 'model' },
@@ -3230,7 +3584,7 @@ const createAdminCrudTableColumnSchema = definitionSchema((ctx) => z$8.object({
3230
3584
  const createAdminCrudEmbeddedObjectSchema = definitionSchema((ctx) => z$8.object({
3231
3585
  id: z$8.string().min(1),
3232
3586
  name: z$8.string().min(1),
3233
- modelRef: zRef(z$8.string().min(1), {
3587
+ modelRef: ctx.withRef({
3234
3588
  type: modelEntityType,
3235
3589
  onDelete: 'RESTRICT',
3236
3590
  }),
@@ -3243,7 +3597,7 @@ const createAdminCrudEmbeddedObjectSchema = definitionSchema((ctx) => z$8.object
3243
3597
  const createAdminCrudEmbeddedListSchema = definitionSchema((ctx) => z$8.object({
3244
3598
  id: z$8.string().min(1),
3245
3599
  name: z$8.string().min(1),
3246
- modelRef: zRef(z$8.string().min(1), {
3600
+ modelRef: ctx.withRef({
3247
3601
  type: modelEntityType,
3248
3602
  onDelete: 'RESTRICT',
3249
3603
  }),
@@ -3258,7 +3612,7 @@ const createAdminCrudEmbeddedListSchema = definitionSchema((ctx) => z$8.object({
3258
3612
  fields: z$8.array(createAdminCrudInputSchema(ctx)),
3259
3613
  }),
3260
3614
  }));
3261
- const createAdminCrudEmbeddedFormSchema = definitionSchema((ctx) => zRefBuilder(z$8.discriminatedUnion('type', [
3615
+ const createAdminCrudEmbeddedFormSchema = definitionSchema((ctx) => ctx.withRefBuilder(z$8.discriminatedUnion('type', [
3262
3616
  createAdminCrudEmbeddedObjectSchema(ctx),
3263
3617
  createAdminCrudEmbeddedListSchema(ctx),
3264
3618
  ]), (builder) => {
@@ -3269,10 +3623,9 @@ const createAdminCrudEmbeddedFormSchema = definitionSchema((ctx) => zRefBuilder(
3269
3623
  builder.addPathToContext('modelRef', modelEntityType, 'model');
3270
3624
  }));
3271
3625
  // Admin Section
3272
- const createAdminCrudSectionSchema = definitionSchema((ctx) => zRefBuilder(z$8.object({
3273
- ...baseAdminSectionValidators,
3626
+ const createAdminCrudSectionSchema = definitionSchema((ctx) => ctx.withRefBuilder(createBaseAdminSectionValidators(ctx).and(z$8.object({
3274
3627
  type: z$8.literal('crud'),
3275
- modelRef: zRef(z$8.string().min(1), {
3628
+ modelRef: ctx.withRef({
3276
3629
  type: modelEntityType,
3277
3630
  onDelete: 'RESTRICT',
3278
3631
  }),
@@ -3283,13 +3636,15 @@ const createAdminCrudSectionSchema = definitionSchema((ctx) => zRefBuilder(z$8.o
3283
3636
  form: z$8.object({
3284
3637
  fields: z$8.array(createAdminCrudInputSchema(ctx)),
3285
3638
  }),
3286
- embeddedForms: z$8.array(createAdminCrudEmbeddedFormSchema(ctx)).optional(),
3287
- }), (builder) => {
3639
+ embeddedForms: z$8
3640
+ .array(createAdminCrudEmbeddedFormSchema(ctx))
3641
+ .optional(),
3642
+ })), (builder) => {
3288
3643
  builder.addPathToContext('modelRef', modelEntityType, 'model');
3289
3644
  }));
3290
3645
 
3291
3646
  const {z: z$7} = await importShared('zod');
3292
- const createAdminSectionSchema = definitionSchema((ctx) => zRefBuilder(createAdminCrudSectionSchema(ctx), (builder) => {
3647
+ const createAdminSectionSchema = definitionSchema((ctx) => ctx.withRefBuilder(createAdminCrudSectionSchema(ctx), (builder) => {
3293
3648
  builder.addEntity({
3294
3649
  type: adminSectionEntityType,
3295
3650
  parentPath: { context: 'app' },
@@ -3300,7 +3655,7 @@ const createAdminAppSchema = definitionSchema((ctx) => z$7.object({
3300
3655
  ...baseAppValidators,
3301
3656
  type: z$7.literal('admin'),
3302
3657
  allowedRoles: z$7
3303
- .array(zRef(z$7.string(), {
3658
+ .array(ctx.withRef({
3304
3659
  type: authRoleEntityType,
3305
3660
  onDelete: 'DELETE',
3306
3661
  }))
@@ -3323,14 +3678,14 @@ const createBackendAppSchema = definitionSchema(() => z$6.object({
3323
3678
  const backendAppEntryType = createAppEntryType('backend');
3324
3679
 
3325
3680
  const {z: z$5} = await importShared('zod');
3326
- const createWebAppSchema = definitionSchema(() => z$5.object({
3681
+ const createWebAppSchema = definitionSchema((ctx) => z$5.object({
3327
3682
  ...baseAppValidators,
3328
3683
  type: z$5.literal('web'),
3329
3684
  includeAuth: z$5.boolean().optional(),
3330
3685
  title: z$5.string().optional(),
3331
3686
  description: z$5.string().optional(),
3332
3687
  allowedRoles: z$5
3333
- .array(zRef(z$5.string().min(1), {
3688
+ .array(ctx.withRef({
3334
3689
  type: authRoleEntityType,
3335
3690
  onDelete: 'DELETE',
3336
3691
  }))
@@ -3342,28 +3697,31 @@ const webAppEntryType = createAppEntryType('web');
3342
3697
 
3343
3698
  const {z: z$4} = await importShared('zod');
3344
3699
  const basePluginDefinitionSchema = z$4.object({
3345
- id: z$4.string().min(1),
3700
+ id: z$4.string(),
3346
3701
  packageName: z$4.string(),
3347
3702
  name: z$4.string(),
3348
3703
  version: z$4.string(),
3349
3704
  config: z$4.unknown(),
3350
3705
  configSchemaVersion: z$4.number().optional(),
3351
3706
  });
3352
- const createPluginWithConfigSchema = definitionSchema(() => zWithPlugins((plugins, data) => {
3353
- const parsedBasePlugin = basePluginDefinitionSchema.parse(data);
3354
- const pluginKey = pluginEntityType.keyFromId(parsedBasePlugin.id);
3355
- const configSchema = plugins
3707
+ const createPluginWithConfigSchema = definitionSchema((ctx) => ctx
3708
+ .withEnt(basePluginDefinitionSchema.passthrough(), {
3709
+ type: pluginEntityType,
3710
+ })
3711
+ .transform((data, parseCtx) => {
3712
+ const pluginKey = pluginEntityType.keyFromId(data.id);
3713
+ const createConfigSchema = ctx.plugins
3356
3714
  .getPluginSpec(pluginConfigSpec)
3357
- .getSchema(pluginKey);
3358
- const pluginDefinitionWithEnt = zEnt(basePluginDefinitionSchema, {
3359
- type: pluginEntityType,
3360
- });
3361
- if (!configSchema) {
3362
- return pluginDefinitionWithEnt;
3715
+ .getSchemaCreator(pluginKey);
3716
+ let pluginDefinitionSchema = basePluginDefinitionSchema;
3717
+ if (createConfigSchema) {
3718
+ pluginDefinitionSchema = pluginDefinitionSchema.extend({
3719
+ config: createConfigSchema(ctx),
3720
+ });
3363
3721
  }
3364
- return pluginDefinitionWithEnt.and(z$4.object({
3365
- config: configSchema,
3366
- }));
3722
+ return pluginDefinitionSchema.parse(data, {
3723
+ path: parseCtx.path,
3724
+ });
3367
3725
  }));
3368
3726
  const createPluginsSchema = definitionSchema((ctx) => z$4.array(createPluginWithConfigSchema(ctx)));
3369
3727
 
@@ -3414,7 +3772,7 @@ const createSettingsSchema = definitionSchema((ctx) => z$2.object({
3414
3772
  }));
3415
3773
 
3416
3774
  const {z: z$1} = await importShared('zod');
3417
- const createAppSchema = definitionSchema((ctx) => zRefBuilder(z$1.discriminatedUnion('type', [
3775
+ const createAppSchema = definitionSchema((ctx) => ctx.withRefBuilder(z$1.discriminatedUnion('type', [
3418
3776
  createBackendAppSchema(ctx),
3419
3777
  createWebAppSchema(ctx),
3420
3778
  createAdminAppSchema(ctx),
@@ -3647,7 +4005,10 @@ function createPluginImplementationStore(pluginStore, projectDefinition) {
3647
4005
  function createProjectDefinitionSchemaWithContext(projectDefinition, context) {
3648
4006
  const { pluginStore } = context;
3649
4007
  const pluginImplementationStore = createPluginImplementationStore(pluginStore, projectDefinition);
3650
- return zPluginWrapper(createProjectDefinitionSchema({ plugins: pluginImplementationStore }), pluginImplementationStore);
4008
+ const definitionContext = createDefinitionSchemaParserContext({
4009
+ plugins: pluginImplementationStore,
4010
+ });
4011
+ return createProjectDefinitionSchema(definitionContext);
3651
4012
  }
3652
4013
  function parseProjectDefinitionWithContext(projectDefinition, context) {
3653
4014
  const schema = createProjectDefinitionSchemaWithContext(projectDefinition, context);
@@ -3661,9 +4022,10 @@ function parseProjectDefinitionWithContext(projectDefinition, context) {
3661
4022
  * @returns The parsed project definition with entities/references
3662
4023
  */
3663
4024
  function parseProjectDefinitionWithReferences(projectDefinition, context) {
3664
- const schema = createProjectDefinitionSchemaWithContext(projectDefinition, context);
3665
- const definition = parseSchemaWithReferences(schema, projectDefinition);
3666
- return { definition, pluginStore: schema._def.pluginStore };
4025
+ const { pluginStore } = context;
4026
+ const pluginImplementationStore = createPluginImplementationStore(pluginStore, projectDefinition);
4027
+ const definition = parseSchemaWithTransformedReferences(createProjectDefinitionSchema, projectDefinition, { plugins: pluginImplementationStore });
4028
+ return { definition, pluginStore: pluginImplementationStore };
3667
4029
  }
3668
4030
 
3669
4031
  /**
@@ -3745,8 +4107,9 @@ class ProjectDefinitionContainer {
3745
4107
  */
3746
4108
  fixRefDeletions(setter) {
3747
4109
  const newDefinition = produce(setter)(this.definition);
3748
- const schemaWithContext = createProjectDefinitionSchemaWithContext(newDefinition, this.parserContext);
3749
- return fixRefDeletions(schemaWithContext, newDefinition);
4110
+ return fixRefDeletions(createProjectDefinitionSchema, newDefinition, {
4111
+ plugins: this.pluginStore,
4112
+ });
3750
4113
  }
3751
4114
  /**
3752
4115
  * Serializes the project definition resolving references to their names for easier reading.
@@ -3775,8 +4138,8 @@ class ProjectDefinitionContainer {
3775
4138
  * @returns A new ProjectDefinitionContainer
3776
4139
  */
3777
4140
  static fromSerializedConfig(config, context) {
3778
- const projectDefinitionSchemaWithContext = createProjectDefinitionSchemaWithContext(config, context);
3779
- return new ProjectDefinitionContainer(deserializeSchemaWithReferences(projectDefinitionSchemaWithContext, config), context, projectDefinitionSchemaWithContext.pluginStore);
4141
+ const plugins = createPluginImplementationStore(context.pluginStore, config);
4142
+ return new ProjectDefinitionContainer(deserializeSchemaWithTransformedReferences(createProjectDefinitionSchema, config, { plugins }), context, plugins);
3780
4143
  }
3781
4144
  }
3782
4145
 
@@ -8735,6 +9098,25 @@ const migration014MigratePluginIds = createSchemaMigration({
8735
9098
  },
8736
9099
  });
8737
9100
 
9101
+ const migration015NullParentRefs = createSchemaMigration({
9102
+ version: 15,
9103
+ name: 'nullParentRefs',
9104
+ description: 'Convert null parentRefs to undefined in features',
9105
+ migrate: (config) => {
9106
+ if (!config.features) {
9107
+ return config;
9108
+ }
9109
+ const features = config.features.map((feature) => ({
9110
+ ...feature,
9111
+ parentRef: feature.parentRef ?? undefined,
9112
+ }));
9113
+ return {
9114
+ ...config,
9115
+ features,
9116
+ };
9117
+ },
9118
+ });
9119
+
8738
9120
  const SCHEMA_MIGRATIONS = [
8739
9121
  migration005PrimaryUniqueRefs,
8740
9122
  migration006IndividualServiceControllers,
@@ -8746,6 +9128,7 @@ const SCHEMA_MIGRATIONS = [
8746
9128
  migration012MigrateAuthConfig,
8747
9129
  migration013MoveGeneralSettings,
8748
9130
  migration014MigratePluginIds,
9131
+ migration015NullParentRefs,
8749
9132
  ];
8750
9133
  function isMigrateableProjectDefinition(projectDefinition) {
8751
9134
  return (typeof projectDefinition === 'object' &&
@@ -8822,11 +9205,7 @@ function createTestProjectDefinitionContainer(input = {}) {
8822
9205
  availablePlugins: [],
8823
9206
  };
8824
9207
  const pluginImplementationStore = new PluginImplementationStore({});
8825
- const projectDefinitionSchema = createProjectDefinitionSchema({
8826
- plugins: pluginImplementationStore,
8827
- });
8828
- const schemaWithPlugins = zPluginWrapper(projectDefinitionSchema, pluginImplementationStore);
8829
- const resolvedRefPayload = deserializeSchemaWithReferences(schemaWithPlugins, createTestProjectDefinitionInput(input));
9208
+ const resolvedRefPayload = deserializeSchemaWithTransformedReferences(createProjectDefinitionSchema, createTestProjectDefinitionInput(input), { plugins: pluginImplementationStore });
8830
9209
  return new ProjectDefinitionContainer(resolvedRefPayload, { pluginStore }, pluginImplementationStore);
8831
9210
  }
8832
9211
 
@@ -9888,5 +10267,5 @@ function generateDefaultTheme() {
9888
10267
  };
9889
10268
  }
9890
10269
 
9891
- export { AVAILABLE_FLAGS, AppUtils, BUILT_IN_ADMIN_CRUD_INPUTS, BUILT_IN_TRANSFORMERS, COLOR_PALETTES, EnumUtils, FIXED_COLOR_MAPPINGS, ModelFieldUtils, ModelTransformerUtils, ModelUtils, PALETTE_SHADES, PluginImplementationStore, PluginUtils, ProjectDefinitionContainer, REFERENTIAL_ACTIONS, SCALAR_FIELD_TYPES, SCHEMA_MIGRATIONS, SchemaMigrationError, THEME_COLORS, THEME_COLOR_KEYS, VALIDATORS, ZodRefWrapper, ZodWithPlugins, adminAppEntryType, adminCrudDisplayTypes, adminCrudEmbeddedFormEntityType, adminCrudEmbeddedInputType, adminCrudEmbeddedLocalInputType, adminCrudInputCompilerSpec, adminCrudInputSpec, adminSectionEntityType, appCompilerSpec, appEntityType, authConfigSpec, authRoleEntityType, backendAppEntryType, baseAdminCrudInputSchema, baseAdminSectionValidators, baseAppSchema, baseAppValidators, basePluginDefinitionSchema, baseTransformerFields, baseTransformerSchema, convertColorNameToOklch, convertHexToOklch, convertOklchToColorName, convertOklchToHex, createAdminAppSchema, createAdminCrudDisplaySchema, createAdminCrudEmbeddedFormSchema, createAdminCrudEmbeddedInputSchema, createAdminCrudEmbeddedListSchema, createAdminCrudEmbeddedLocalInputSchema, createAdminCrudEmbeddedObjectSchema, createAdminCrudEnumInputSchema, createAdminCrudForeignDisplaySchema, createAdminCrudForeignInputSchema, createAdminCrudInputCompilerImplementation, createAdminCrudInputImplementation, createAdminCrudInputSchema, createAdminCrudInputType, createAdminCrudPasswordInputSchema, createAdminCrudSectionSchema, createAdminCrudTableColumnSchema, createAdminCrudTextDisplaySchema, createAdminCrudTextInputSchema, createAdminSectionSchema, createAppCompiler, createAppCompilerPlugin, createAppEntryType, createAppSchema, createBackendAppSchema, createDefinitionEntityNameResolver, createEmbeddedRelationTransformerSchema, createEntityType, createEnumBaseSchema, createEnumSchema, createEnumValueSchema, createFeaturesSchema, createModelBaseSchema, createModelGraphqlSchema, createModelRelationFieldSchema, createModelScalarFieldSchema, createModelSchema, createModelServiceSchema, createModelTransformerCompilerImplementation, createModelTransformerImplementation, createModelTransformerType, createModelUniqueConstraintSchema, createPasswordTransformerSchema, createPlatformPluginExport, createPluginConfigImplementation, createPluginImplementationStore, createPluginSpec, createPluginWithConfigSchema, createPluginsSchema, createProjectDefinitionSchema, createProjectDefinitionSchemaWithContext, createSettingsSchema, createTemplateExtractorSchema, createTestProjectDefinition, createTestProjectDefinitionContainer, createTestProjectDefinitionInput, createThemeSchema, createTransformerSchema, createWebAppSchema, createWebConfigImplementation, definitionSchema, deserializeSchemaWithReferences, featureEntityType, fixRefDeletions, generalSettingsSchema, generateCssFromThemeConfig, generateDefaultTheme, generateThemeColorsFromShade, getBackendRelativePath, getDefaultThemeColorFromShade, getLatestMigrationVersion, initializePlugins, isMigrateableProjectDefinition, modelEntityType, modelEnumEntityType, modelEnumValueEntityType, modelForeignRelationEntityType, modelLocalRelationEntityType, modelScalarFieldEntityType, modelTransformerCompilerSpec, modelTransformerEntityType, modelTransformerSpec, modelUniqueConstraintEntityType, oklchColor, paletteSchema, palettesSchema, parseOklch, parseProjectDefinitionWithContext, parseProjectDefinitionWithReferences, pluginConfigSpec, pluginEntityType, pluginManifestJsonSchema, pluginMetadataSchema, pluginSpecDependencySchema, pluginSpecSupportSchema, runPluginMigrations, runSchemaMigrations, serializeSchema, serializeSchemaFromRefPayload, stripEmptyGeneratorChildren, stripUndefinedValues, themeColorSchema, undefinedIfEmpty, undefinedIfFalsy, webAppEntryType, webConfigSpec, zEnt, zPluginWrapper, zRef, zRefBuilder, zRefId, zWithPlugins };
9892
- //# sourceMappingURL=project-builder-lib-BAwM_-SS.js.map
10270
+ export { AVAILABLE_FLAGS, AppUtils, BUILT_IN_ADMIN_CRUD_INPUTS, BUILT_IN_TRANSFORMERS, COLOR_PALETTES, DefinitionRefBuilder, EnumUtils, FIXED_COLOR_MAPPINGS, ModelFieldUtils, ModelTransformerUtils, ModelUtils, PALETTE_SHADES, PluginImplementationStore, PluginUtils, ProjectDefinitionContainer, REFERENTIAL_ACTIONS, SCALAR_FIELD_TYPES, SCHEMA_MIGRATIONS, SchemaMigrationError, THEME_COLORS, THEME_COLOR_KEYS, VALIDATORS, adminAppEntryType, adminCrudDisplayTypes, adminCrudEmbeddedFormEntityType, adminCrudEmbeddedInputType, adminCrudEmbeddedLocalInputType, adminCrudInputCompilerSpec, adminCrudInputSpec, adminSectionEntityType, appCompilerSpec, appEntityType, authConfigSpec, authRoleEntityType, backendAppEntryType, baseAdminCrudInputSchema, baseAppSchema, baseAppValidators, basePluginDefinitionSchema, baseTransformerFields, baseTransformerSchema, convertColorNameToOklch, convertHexToOklch, convertOklchToColorName, convertOklchToHex, createAdminAppSchema, createAdminCrudDisplaySchema, createAdminCrudEmbeddedFormSchema, createAdminCrudEmbeddedInputSchema, createAdminCrudEmbeddedListSchema, createAdminCrudEmbeddedLocalInputSchema, createAdminCrudEmbeddedObjectSchema, createAdminCrudEnumInputSchema, createAdminCrudForeignDisplaySchema, createAdminCrudForeignInputSchema, createAdminCrudInputCompilerImplementation, createAdminCrudInputImplementation, createAdminCrudInputSchema, createAdminCrudInputType, createAdminCrudPasswordInputSchema, createAdminCrudSectionSchema, createAdminCrudTableColumnSchema, createAdminCrudTextDisplaySchema, createAdminCrudTextInputSchema, createAdminSectionSchema, createAppCompiler, createAppCompilerPlugin, createAppEntryType, createAppSchema, createBackendAppSchema, createBaseAdminSectionValidators, createDefinitionEntityNameResolver, createDefinitionSchemaParserContext, createEmbeddedRelationTransformerSchema, createEntityType, createEnumBaseSchema, createEnumSchema, createEnumValueSchema, createFeaturesSchema, createModelBaseSchema, createModelGraphqlSchema, createModelRelationFieldSchema, createModelScalarFieldSchema, createModelSchema, createModelServiceSchema, createModelTransformerCompilerImplementation, createModelTransformerImplementation, createModelTransformerType, createModelUniqueConstraintSchema, createPasswordTransformerSchema, createPlatformPluginExport, createPluginConfigImplementation, createPluginImplementationStore, createPluginSpec, createPluginWithConfigSchema, createPluginsSchema, createProjectDefinitionSchema, createProjectDefinitionSchemaWithContext, createSettingsSchema, createTemplateExtractorSchema, createTestProjectDefinition, createTestProjectDefinitionContainer, createTestProjectDefinitionInput, createThemeSchema, createTransformerSchema, createWebAppSchema, createWebConfigImplementation, definitionSchema, deserializeSchemaWithTransformedReferences, extractDefinitionRefs, extractDefinitionRefsRecursive, featureEntityType, fixRefDeletions, generalSettingsSchema, generateCssFromThemeConfig, generateDefaultTheme, generateThemeColorsFromShade, getBackendRelativePath, getDefaultThemeColorFromShade, getLatestMigrationVersion, initializePlugins, isMigrateableProjectDefinition, modelEntityType, modelEnumEntityType, modelEnumValueEntityType, modelForeignRelationEntityType, modelLocalRelationEntityType, modelScalarFieldEntityType, modelTransformerCompilerSpec, modelTransformerEntityType, modelTransformerSpec, modelUniqueConstraintEntityType, oklchColor, paletteSchema, palettesSchema, parseOklch, parseProjectDefinitionWithContext, parseProjectDefinitionWithReferences, pluginConfigSpec, pluginEntityType, pluginManifestJsonSchema, pluginMetadataSchema, pluginSpecDependencySchema, pluginSpecSupportSchema, runPluginMigrations, runSchemaMigrations, serializeSchema, serializeSchemaFromRefPayload, stripEmptyGeneratorChildren, stripUndefinedValues, themeColorSchema, undefinedIfEmpty, undefinedIfFalsy, webAppEntryType, webConfigSpec };
10271
+ //# sourceMappingURL=project-builder-lib-SOC0hDo0.js.map