@baseplate-dev/plugin-auth 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +390 -0
- package/dist/auth/core/common.d.ts +7 -0
- package/dist/auth/core/common.d.ts.map +1 -0
- package/dist/auth/core/common.js +26 -0
- package/dist/auth/core/common.js.map +1 -0
- package/dist/auth/core/components/auth-definition-editor.d.ts +5 -0
- package/dist/auth/core/components/auth-definition-editor.d.ts.map +1 -0
- package/dist/auth/core/components/auth-definition-editor.js +57 -0
- package/dist/auth/core/components/auth-definition-editor.js.map +1 -0
- package/dist/auth/core/components/role-editor-form.d.ts +10 -0
- package/dist/auth/core/components/role-editor-form.d.ts.map +1 -0
- package/dist/auth/core/components/role-editor-form.js +27 -0
- package/dist/auth/core/components/role-editor-form.js.map +1 -0
- package/dist/auth/core/node.d.ts +5 -0
- package/dist/auth/core/node.d.ts.map +1 -0
- package/dist/auth/core/node.js +58 -0
- package/dist/auth/core/node.js.map +1 -0
- package/dist/auth/core/schema/models.d.ts +9 -0
- package/dist/auth/core/schema/models.d.ts.map +1 -0
- package/dist/auth/core/schema/models.js +187 -0
- package/dist/auth/core/schema/models.js.map +1 -0
- package/dist/auth/core/schema/plugin-definition.d.ts +88 -0
- package/dist/auth/core/schema/plugin-definition.d.ts.map +1 -0
- package/dist/auth/core/schema/plugin-definition.js +29 -0
- package/dist/auth/core/schema/plugin-definition.js.map +1 -0
- package/dist/auth/core/web.d.ts +6 -0
- package/dist/auth/core/web.d.ts.map +1 -0
- package/dist/auth/core/web.js +14 -0
- package/dist/auth/core/web.js.map +1 -0
- package/dist/auth/generators/fastify/auth-module/auth-module.generator.d.ts +65 -0
- package/dist/auth/generators/fastify/auth-module/auth-module.generator.d.ts.map +1 -0
- package/dist/auth/generators/fastify/auth-module/auth-module.generator.js +62 -0
- package/dist/auth/generators/fastify/auth-module/auth-module.generator.js.map +1 -0
- package/dist/auth/generators/fastify/auth-module/generated/ts-templates.d.ts +96 -0
- package/dist/auth/generators/fastify/auth-module/generated/ts-templates.d.ts.map +1 -0
- package/dist/auth/generators/fastify/auth-module/generated/ts-templates.js +94 -0
- package/dist/auth/generators/fastify/auth-module/generated/ts-templates.js.map +1 -0
- package/dist/auth/generators/fastify/auth-module/templates/management.ts +22 -0
- package/dist/auth/generators/fastify/auth-module/templates/schema/user-session-payload.object-type.ts +23 -0
- package/dist/auth/generators/fastify/auth-module/templates/schema/user-session.mutations.ts +22 -0
- package/dist/auth/generators/fastify/auth-module/templates/schema/user-session.queries.ts +20 -0
- package/dist/auth/generators/fastify/auth-module/templates/services/user-session.service.ts +251 -0
- package/dist/auth/generators/fastify/auth-module/templates/user-session.constants.ts +19 -0
- package/dist/auth/generators/fastify/auth-module/templates/user-session.service.ts +101 -0
- package/dist/auth/generators/fastify/auth-module/templates/utils/cookie-signer.ts +71 -0
- package/dist/auth/generators/fastify/auth-module/templates/utils/session-cookie.ts +42 -0
- package/dist/auth/generators/fastify/auth-module/templates/utils/verify-request-origin.ts +45 -0
- package/dist/auth/generators/fastify/index.d.ts +2 -0
- package/dist/auth/generators/fastify/index.d.ts.map +1 -0
- package/dist/auth/generators/fastify/index.js +2 -0
- package/dist/auth/generators/fastify/index.js.map +1 -0
- package/dist/auth/generators/index.d.ts +2 -0
- package/dist/auth/generators/index.d.ts.map +1 -0
- package/dist/auth/generators/index.js +2 -0
- package/dist/auth/generators/index.js.map +1 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/metadata.json +8 -0
- package/dist/auth/static/icon.svg +1 -0
- package/dist/auth0/constants/packages.d.ts +6 -0
- package/dist/auth0/constants/packages.d.ts.map +1 -0
- package/dist/auth0/constants/packages.js +6 -0
- package/dist/auth0/constants/packages.js.map +1 -0
- package/dist/auth0/core/common.d.ts +7 -0
- package/dist/auth0/core/common.d.ts.map +1 -0
- package/dist/auth0/core/common.js +28 -0
- package/dist/auth0/core/common.js.map +1 -0
- package/dist/auth0/core/components/auth-definition-editor.d.ts +5 -0
- package/dist/auth0/core/components/auth-definition-editor.d.ts.map +1 -0
- package/dist/auth0/core/components/auth-definition-editor.js +57 -0
- package/dist/auth0/core/components/auth-definition-editor.js.map +1 -0
- package/dist/auth0/core/components/role-dialog.d.ts +14 -0
- package/dist/auth0/core/components/role-dialog.d.ts.map +1 -0
- package/dist/auth0/core/components/role-dialog.js +27 -0
- package/dist/auth0/core/components/role-dialog.js.map +1 -0
- package/dist/auth0/core/components/role-editor-form.d.ts +10 -0
- package/dist/auth0/core/components/role-editor-form.d.ts.map +1 -0
- package/dist/auth0/core/components/role-editor-form.js +52 -0
- package/dist/auth0/core/components/role-editor-form.js.map +1 -0
- package/dist/auth0/core/node.d.ts +5 -0
- package/dist/auth0/core/node.d.ts.map +1 -0
- package/dist/auth0/core/node.js +86 -0
- package/dist/auth0/core/node.js.map +1 -0
- package/dist/auth0/core/schema/migrations.d.ts +3 -0
- package/dist/auth0/core/schema/migrations.d.ts.map +1 -0
- package/dist/auth0/core/schema/migrations.js +17 -0
- package/dist/auth0/core/schema/migrations.js.map +1 -0
- package/dist/auth0/core/schema/models.d.ts +6 -0
- package/dist/auth0/core/schema/models.d.ts.map +1 -0
- package/dist/auth0/core/schema/models.js +33 -0
- package/dist/auth0/core/schema/models.js.map +1 -0
- package/dist/auth0/core/schema/plugin-definition.d.ts +73 -0
- package/dist/auth0/core/schema/plugin-definition.d.ts.map +1 -0
- package/dist/auth0/core/schema/plugin-definition.js +17 -0
- package/dist/auth0/core/schema/plugin-definition.js.map +1 -0
- package/dist/auth0/core/web.d.ts +6 -0
- package/dist/auth0/core/web.d.ts.map +1 -0
- package/dist/auth0/core/web.js +14 -0
- package/dist/auth0/core/web.js.map +1 -0
- package/dist/auth0/generators/fastify/auth0-module/auth0-module.generator.d.ts +67 -0
- package/dist/auth0/generators/fastify/auth0-module/auth0-module.generator.d.ts.map +1 -0
- package/dist/auth0/generators/fastify/auth0-module/auth0-module.generator.js +125 -0
- package/dist/auth0/generators/fastify/auth0-module/auth0-module.generator.js.map +1 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-maps.d.ts +3 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-maps.d.ts.map +1 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-maps.js +12 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-maps.js.map +1 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-templates.d.ts +43 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-templates.d.ts.map +1 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-templates.js +25 -0
- package/dist/auth0/generators/fastify/auth0-module/generated/ts-templates.js.map +1 -0
- package/dist/auth0/generators/fastify/auth0-module/templates/management.ts +22 -0
- package/dist/auth0/generators/fastify/auth0-module/templates/user-session.service.ts +101 -0
- package/dist/auth0/generators/fastify/index.d.ts +2 -0
- package/dist/auth0/generators/fastify/index.d.ts.map +1 -0
- package/dist/auth0/generators/fastify/index.js +2 -0
- package/dist/auth0/generators/fastify/index.js.map +1 -0
- package/dist/auth0/generators/index.d.ts +3 -0
- package/dist/auth0/generators/index.d.ts.map +1 -0
- package/dist/auth0/generators/index.js +3 -0
- package/dist/auth0/generators/index.js.map +1 -0
- package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.d.ts +10 -0
- package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.js +41 -0
- package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.js.map +1 -0
- package/dist/auth0/generators/react/auth0-apollo/templates/auth-link.ts +11 -0
- package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.d.ts +61 -0
- package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.js +59 -0
- package/dist/auth0/generators/react/auth0-callback/auth0-callback.generator.js.map +1 -0
- package/dist/auth0/generators/react/auth0-callback/generated/ts-templates.d.ts +106 -0
- package/dist/auth0/generators/react/auth0-callback/generated/ts-templates.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-callback/generated/ts-templates.js +28 -0
- package/dist/auth0/generators/react/auth0-callback/generated/ts-templates.js.map +1 -0
- package/dist/auth0/generators/react/auth0-callback/templates/auth0-callback.page.tsx +61 -0
- package/dist/auth0/generators/react/auth0-callback/templates/signup.page.tsx +48 -0
- package/dist/auth0/generators/react/auth0-components/auth0-components.generator.d.ts +53 -0
- package/dist/auth0/generators/react/auth0-components/auth0-components.generator.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-components/auth0-components.generator.js +44 -0
- package/dist/auth0/generators/react/auth0-components/auth0-components.generator.js.map +1 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-import-maps.d.ts +3 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-import-maps.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-import-maps.js +12 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-import-maps.js.map +1 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-templates.d.ts +45 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-templates.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-templates.js +13 -0
- package/dist/auth0/generators/react/auth0-components/generated/ts-templates.js.map +1 -0
- package/dist/auth0/generators/react/auth0-components/templates/RequireAuth.tsx +22 -0
- package/dist/auth0/generators/react/auth0-hooks/auth0-hooks.generator.d.ts +28 -0
- package/dist/auth0/generators/react/auth0-hooks/auth0-hooks.generator.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/auth0-hooks.generator.js +65 -0
- package/dist/auth0/generators/react/auth0-hooks/auth0-hooks.generator.js.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/text-templates.d.ts +8 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/text-templates.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/text-templates.js +12 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/text-templates.js.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-import-maps.d.ts +3 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-import-maps.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-import-maps.js +16 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-import-maps.js.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-templates.d.ts +33 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-templates.d.ts.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-templates.js +50 -0
- package/dist/auth0/generators/react/auth0-hooks/generated/ts-templates.js.map +1 -0
- package/dist/auth0/generators/react/auth0-hooks/templates/useCurrentUser.gql +10 -0
- package/dist/auth0/generators/react/auth0-hooks/templates/useCurrentUser.ts +29 -0
- package/dist/auth0/generators/react/auth0-hooks/templates/useLogOut.ts +14 -0
- package/dist/auth0/generators/react/auth0-hooks/templates/useRequiredUserId.ts +11 -0
- package/dist/auth0/generators/react/auth0-hooks/templates/useSession.ts +23 -0
- package/dist/auth0/generators/react/index.d.ts +6 -0
- package/dist/auth0/generators/react/index.d.ts.map +1 -0
- package/dist/auth0/generators/react/index.js +6 -0
- package/dist/auth0/generators/react/index.js.map +1 -0
- package/dist/auth0/generators/react/react-auth0/react-auth0.generator.d.ts +23 -0
- package/dist/auth0/generators/react/react-auth0/react-auth0.generator.d.ts.map +1 -0
- package/dist/auth0/generators/react/react-auth0/react-auth0.generator.js +64 -0
- package/dist/auth0/generators/react/react-auth0/react-auth0.generator.js.map +1 -0
- package/dist/auth0/metadata.json +8 -0
- package/dist/auth0/static/icon.svg +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/roles/constants.d.ts +4 -0
- package/dist/roles/constants.d.ts.map +1 -0
- package/dist/roles/constants.js +25 -0
- package/dist/roles/constants.js.map +1 -0
- package/dist/roles/index.d.ts +3 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/index.js +3 -0
- package/dist/roles/index.js.map +1 -0
- package/dist/roles/schema.d.ts +65 -0
- package/dist/roles/schema.d.ts.map +1 -0
- package/dist/roles/schema.js +43 -0
- package/dist/roles/schema.js.map +1 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/cn.js +2 -0
- package/dist/utils/cn.js.map +1 -0
- package/dist/web/assets/__federation_expose_auth0CoreCommon--n6esVYP.js +54 -0
- package/dist/web/assets/__federation_expose_auth0CoreCommon--n6esVYP.js.map +1 -0
- package/dist/web/assets/__federation_expose_auth0CoreWeb-Ql6gpX5q.js +377 -0
- package/dist/web/assets/__federation_expose_auth0CoreWeb-Ql6gpX5q.js.map +1 -0
- package/dist/web/assets/__federation_fn_import-BiwmVFwy.js +421 -0
- package/dist/web/assets/__federation_fn_import-BiwmVFwy.js.map +1 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-CY8oz43s.js +330 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-CY8oz43s.js.map +1 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-B62IPizQ.js +10559 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-B62IPizQ.js.map +1 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/ui-components-BU2QTWNs.js +12718 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/ui-components-BU2QTWNs.js.map +1 -0
- package/dist/web/assets/__federation_shared_react-dom-Bwq4pLax.js +250 -0
- package/dist/web/assets/__federation_shared_react-dom-Bwq4pLax.js.map +1 -0
- package/dist/web/assets/__federation_shared_react-uocnGSER.js +7 -0
- package/dist/web/assets/__federation_shared_react-uocnGSER.js.map +1 -0
- package/dist/web/assets/__federation_shared_zod-BK7IELHt.js +4380 -0
- package/dist/web/assets/__federation_shared_zod-BK7IELHt.js.map +1 -0
- package/dist/web/assets/index-B1hOKVPw.js +574 -0
- package/dist/web/assets/index-B1hOKVPw.js.map +1 -0
- package/dist/web/assets/index-CgJx-krK.js +95 -0
- package/dist/web/assets/index-CgJx-krK.js.map +1 -0
- package/dist/web/assets/index-l0sNRNKZ.js.map +1 -0
- package/dist/web/assets/index.esm-BcxPd7Ha.js +2584 -0
- package/dist/web/assets/index.esm-BcxPd7Ha.js.map +1 -0
- package/dist/web/assets/model-utils-CbQJy1wE.js +1263 -0
- package/dist/web/assets/model-utils-CbQJy1wE.js.map +1 -0
- package/dist/web/assets/plugin-definition-BQRupXoQ.js +78 -0
- package/dist/web/assets/plugin-definition-BQRupXoQ.js.map +1 -0
- package/dist/web/assets/react-2jQE8aG0.js +47 -0
- package/dist/web/assets/react-2jQE8aG0.js.map +1 -0
- package/dist/web/assets/remoteEntry.js +54 -0
- package/dist/web/assets/remoteEntry.js.map +1 -0
- package/dist/web/assets/style-BdgwWjAf.css +95 -0
- package/dist/web/index.html +24 -0
- package/dist/web-export.d.ts +2 -0
- package/dist/web-export.js +2 -0
- package/dist/web-export.js.map +1 -0
- package/manifest.json +4 -0
- package/package.json +80 -0
|
@@ -0,0 +1,1263 @@
|
|
|
1
|
+
import { importShared } from './__federation_fn_import-BiwmVFwy.js';
|
|
2
|
+
|
|
3
|
+
function createInitializedPluginSpec(spec, implementation) {
|
|
4
|
+
return { spec, implementation };
|
|
5
|
+
}
|
|
6
|
+
function createPluginSpec(name, options) {
|
|
7
|
+
const { platforms, defaultInitializer } = options ?? {};
|
|
8
|
+
return {
|
|
9
|
+
type: 'plugin-spec',
|
|
10
|
+
name,
|
|
11
|
+
platforms: platforms && (Array.isArray(platforms) ? platforms : [platforms]),
|
|
12
|
+
isOptional: false,
|
|
13
|
+
optional() {
|
|
14
|
+
return { ...this, isOptional: true };
|
|
15
|
+
},
|
|
16
|
+
defaultInitializer,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function noop() { }
|
|
21
|
+
|
|
22
|
+
function getSymbols(object) {
|
|
23
|
+
return Object.getOwnPropertySymbols(object).filter(symbol => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isPlainObject(value) {
|
|
27
|
+
if (!value || typeof value !== 'object') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const proto = Object.getPrototypeOf(value);
|
|
31
|
+
const hasObjectPrototype = proto === null ||
|
|
32
|
+
proto === Object.prototype ||
|
|
33
|
+
Object.getPrototypeOf(proto) === null;
|
|
34
|
+
if (!hasObjectPrototype) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getTag(value) {
|
|
41
|
+
if (value == null) {
|
|
42
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
43
|
+
}
|
|
44
|
+
return Object.prototype.toString.call(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const regexpTag = '[object RegExp]';
|
|
48
|
+
const stringTag = '[object String]';
|
|
49
|
+
const numberTag = '[object Number]';
|
|
50
|
+
const booleanTag = '[object Boolean]';
|
|
51
|
+
const argumentsTag = '[object Arguments]';
|
|
52
|
+
const symbolTag = '[object Symbol]';
|
|
53
|
+
const dateTag = '[object Date]';
|
|
54
|
+
const mapTag = '[object Map]';
|
|
55
|
+
const setTag = '[object Set]';
|
|
56
|
+
const arrayTag = '[object Array]';
|
|
57
|
+
const functionTag = '[object Function]';
|
|
58
|
+
const arrayBufferTag = '[object ArrayBuffer]';
|
|
59
|
+
const objectTag = '[object Object]';
|
|
60
|
+
const errorTag = '[object Error]';
|
|
61
|
+
const dataViewTag = '[object DataView]';
|
|
62
|
+
const uint8ArrayTag = '[object Uint8Array]';
|
|
63
|
+
const uint8ClampedArrayTag = '[object Uint8ClampedArray]';
|
|
64
|
+
const uint16ArrayTag = '[object Uint16Array]';
|
|
65
|
+
const uint32ArrayTag = '[object Uint32Array]';
|
|
66
|
+
const bigUint64ArrayTag = '[object BigUint64Array]';
|
|
67
|
+
const int8ArrayTag = '[object Int8Array]';
|
|
68
|
+
const int16ArrayTag = '[object Int16Array]';
|
|
69
|
+
const int32ArrayTag = '[object Int32Array]';
|
|
70
|
+
const bigInt64ArrayTag = '[object BigInt64Array]';
|
|
71
|
+
const float32ArrayTag = '[object Float32Array]';
|
|
72
|
+
const float64ArrayTag = '[object Float64Array]';
|
|
73
|
+
|
|
74
|
+
function eq(value, other) {
|
|
75
|
+
return value === other || (Number.isNaN(value) && Number.isNaN(other));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isEqualWith(a, b, areValuesEqual) {
|
|
79
|
+
return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
|
|
80
|
+
}
|
|
81
|
+
function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
|
|
82
|
+
const result = areValuesEqual(a, b, property, aParent, bParent, stack);
|
|
83
|
+
if (result !== undefined) {
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
if (typeof a === typeof b) {
|
|
87
|
+
switch (typeof a) {
|
|
88
|
+
case 'bigint':
|
|
89
|
+
case 'string':
|
|
90
|
+
case 'boolean':
|
|
91
|
+
case 'symbol':
|
|
92
|
+
case 'undefined': {
|
|
93
|
+
return a === b;
|
|
94
|
+
}
|
|
95
|
+
case 'number': {
|
|
96
|
+
return a === b || Object.is(a, b);
|
|
97
|
+
}
|
|
98
|
+
case 'function': {
|
|
99
|
+
return a === b;
|
|
100
|
+
}
|
|
101
|
+
case 'object': {
|
|
102
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
107
|
+
}
|
|
108
|
+
function areObjectsEqual(a, b, stack, areValuesEqual) {
|
|
109
|
+
if (Object.is(a, b)) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
let aTag = getTag(a);
|
|
113
|
+
let bTag = getTag(b);
|
|
114
|
+
if (aTag === argumentsTag) {
|
|
115
|
+
aTag = objectTag;
|
|
116
|
+
}
|
|
117
|
+
if (bTag === argumentsTag) {
|
|
118
|
+
bTag = objectTag;
|
|
119
|
+
}
|
|
120
|
+
if (aTag !== bTag) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
switch (aTag) {
|
|
124
|
+
case stringTag:
|
|
125
|
+
return a.toString() === b.toString();
|
|
126
|
+
case numberTag: {
|
|
127
|
+
const x = a.valueOf();
|
|
128
|
+
const y = b.valueOf();
|
|
129
|
+
return eq(x, y);
|
|
130
|
+
}
|
|
131
|
+
case booleanTag:
|
|
132
|
+
case dateTag:
|
|
133
|
+
case symbolTag:
|
|
134
|
+
return Object.is(a.valueOf(), b.valueOf());
|
|
135
|
+
case regexpTag: {
|
|
136
|
+
return a.source === b.source && a.flags === b.flags;
|
|
137
|
+
}
|
|
138
|
+
case functionTag: {
|
|
139
|
+
return a === b;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
stack = stack ?? new Map();
|
|
143
|
+
const aStack = stack.get(a);
|
|
144
|
+
const bStack = stack.get(b);
|
|
145
|
+
if (aStack != null && bStack != null) {
|
|
146
|
+
return aStack === b;
|
|
147
|
+
}
|
|
148
|
+
stack.set(a, b);
|
|
149
|
+
stack.set(b, a);
|
|
150
|
+
try {
|
|
151
|
+
switch (aTag) {
|
|
152
|
+
case mapTag: {
|
|
153
|
+
if (a.size !== b.size) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
for (const [key, value] of a.entries()) {
|
|
157
|
+
if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
case setTag: {
|
|
164
|
+
if (a.size !== b.size) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
const aValues = Array.from(a.values());
|
|
168
|
+
const bValues = Array.from(b.values());
|
|
169
|
+
for (let i = 0; i < aValues.length; i++) {
|
|
170
|
+
const aValue = aValues[i];
|
|
171
|
+
const index = bValues.findIndex(bValue => {
|
|
172
|
+
return isEqualWithImpl(aValue, bValue, undefined, a, b, stack, areValuesEqual);
|
|
173
|
+
});
|
|
174
|
+
if (index === -1) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
bValues.splice(index, 1);
|
|
178
|
+
}
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
case arrayTag:
|
|
182
|
+
case uint8ArrayTag:
|
|
183
|
+
case uint8ClampedArrayTag:
|
|
184
|
+
case uint16ArrayTag:
|
|
185
|
+
case uint32ArrayTag:
|
|
186
|
+
case bigUint64ArrayTag:
|
|
187
|
+
case int8ArrayTag:
|
|
188
|
+
case int16ArrayTag:
|
|
189
|
+
case int32ArrayTag:
|
|
190
|
+
case bigInt64ArrayTag:
|
|
191
|
+
case float32ArrayTag:
|
|
192
|
+
case float64ArrayTag: {
|
|
193
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
if (a.length !== b.length) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
for (let i = 0; i < a.length; i++) {
|
|
200
|
+
if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
case arrayBufferTag: {
|
|
207
|
+
if (a.byteLength !== b.byteLength) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
211
|
+
}
|
|
212
|
+
case dataViewTag: {
|
|
213
|
+
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
217
|
+
}
|
|
218
|
+
case errorTag: {
|
|
219
|
+
return a.name === b.name && a.message === b.message;
|
|
220
|
+
}
|
|
221
|
+
case objectTag: {
|
|
222
|
+
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) ||
|
|
223
|
+
(isPlainObject(a) && isPlainObject(b));
|
|
224
|
+
if (!areEqualInstances) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
228
|
+
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
229
|
+
if (aKeys.length !== bKeys.length) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
233
|
+
const propKey = aKeys[i];
|
|
234
|
+
const aProp = a[propKey];
|
|
235
|
+
if (!Object.hasOwn(b, propKey)) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const bProp = b[propKey];
|
|
239
|
+
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
default: {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
stack.delete(a);
|
|
252
|
+
stack.delete(b);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function isEqual(a, b) {
|
|
257
|
+
return isEqualWith(a, b, noop);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes));
|
|
261
|
+
let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
262
|
+
let mask = (2 << Math.log2(alphabet.length - 1)) - 1;
|
|
263
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length);
|
|
264
|
+
return (size = defaultSize) => {
|
|
265
|
+
let id = '';
|
|
266
|
+
while (true) {
|
|
267
|
+
let bytes = getRandom(step);
|
|
268
|
+
let j = step | 0;
|
|
269
|
+
while (j--) {
|
|
270
|
+
id += alphabet[bytes[j] & mask] || '';
|
|
271
|
+
if (id.length >= size) return id
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
let customAlphabet = (alphabet, size = 21) =>
|
|
277
|
+
customRandom(alphabet, size | 0, random);
|
|
278
|
+
|
|
279
|
+
const NUMBERS = '0123456789';
|
|
280
|
+
const LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
|
|
281
|
+
const UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
282
|
+
/**
|
|
283
|
+
* Use custom ID generator for characters that be easily selected
|
|
284
|
+
*/
|
|
285
|
+
const customNanoid = customAlphabet(`${NUMBERS}${LOWERCASE}${UPPERCASE}_`, 12);
|
|
286
|
+
/**
|
|
287
|
+
* Generate a random ID string made up of numbers, lowercase, and uppercase letters
|
|
288
|
+
* @returns A random ID string
|
|
289
|
+
*/
|
|
290
|
+
function randomUid(length = 12) {
|
|
291
|
+
return customNanoid(length);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const {z: z$2} = await importShared('zod');
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Regex for validating kebab case, e.g. "my-project".
|
|
298
|
+
*/
|
|
299
|
+
const KEBAB_CASE_REGEX = /^[a-z0-9-]+$/;
|
|
300
|
+
/**
|
|
301
|
+
* Regex for validating pascal case, e.g. "MyProject".
|
|
302
|
+
*/
|
|
303
|
+
const PASCAL_CASE_REGEX = /^[A-Z][a-zA-Z0-9]*$/;
|
|
304
|
+
/**
|
|
305
|
+
* Regex for validating camel case, e.g. "myProject".
|
|
306
|
+
*/
|
|
307
|
+
const CAMEL_CASE_REGEX = /^[a-z][a-zA-Z0-9]*$/;
|
|
308
|
+
/**
|
|
309
|
+
* Regex for validating constant case, e.g. "MY_PROJECT".
|
|
310
|
+
*/
|
|
311
|
+
const CONSTANT_CASE_REGEX = /^[A-Z][A-Z0-9_]*$/;
|
|
312
|
+
const CASE_VALIDATORS = {
|
|
313
|
+
/**
|
|
314
|
+
* Zod validator for validating kebab case, e.g. "my-project".
|
|
315
|
+
*/
|
|
316
|
+
KEBAB_CASE: z$2.string().regex(KEBAB_CASE_REGEX),
|
|
317
|
+
/**
|
|
318
|
+
* Zod validator for validating pascal case, e.g. "MyProject".
|
|
319
|
+
*/
|
|
320
|
+
PASCAL_CASE: z$2.string().regex(PASCAL_CASE_REGEX),
|
|
321
|
+
/**
|
|
322
|
+
* Zod validator for validating camel case, e.g. "myProject".
|
|
323
|
+
*/
|
|
324
|
+
CAMEL_CASE: z$2.string().regex(CAMEL_CASE_REGEX),
|
|
325
|
+
/**
|
|
326
|
+
* Zod validator for validating constant case, e.g. "MY_PROJECT".
|
|
327
|
+
*/
|
|
328
|
+
CONSTANT_CASE: z$2.string().regex(CONSTANT_CASE_REGEX),
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Definition of an entity type.
|
|
333
|
+
*/
|
|
334
|
+
class DefinitionEntityType {
|
|
335
|
+
/**
|
|
336
|
+
* Creates a new entity type.
|
|
337
|
+
*
|
|
338
|
+
* @param name - The name of the entity type.
|
|
339
|
+
* @param prefix - The prefix of the entity type to use in the ID, defaults to the name.
|
|
340
|
+
* @param parentType - The type of the parent entity if any
|
|
341
|
+
*/
|
|
342
|
+
constructor(name, prefix, parentType) {
|
|
343
|
+
Object.defineProperty(this, "name", {
|
|
344
|
+
enumerable: true,
|
|
345
|
+
configurable: true,
|
|
346
|
+
writable: true,
|
|
347
|
+
value: name
|
|
348
|
+
});
|
|
349
|
+
Object.defineProperty(this, "parentType", {
|
|
350
|
+
enumerable: true,
|
|
351
|
+
configurable: true,
|
|
352
|
+
writable: true,
|
|
353
|
+
value: parentType
|
|
354
|
+
});
|
|
355
|
+
Object.defineProperty(this, "prefix", {
|
|
356
|
+
enumerable: true,
|
|
357
|
+
configurable: true,
|
|
358
|
+
writable: true,
|
|
359
|
+
value: void 0
|
|
360
|
+
});
|
|
361
|
+
this.prefix = prefix ?? name.split('/').pop() ?? name;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Generates a new ID for the entity type.
|
|
365
|
+
*
|
|
366
|
+
* @returns The new ID.
|
|
367
|
+
*/
|
|
368
|
+
generateNewId() {
|
|
369
|
+
return `${this.prefix}:${randomUid()}`;
|
|
370
|
+
}
|
|
371
|
+
fromUid(uid) {
|
|
372
|
+
if (!uid) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
return `${this.prefix}:${uid}`;
|
|
376
|
+
}
|
|
377
|
+
toUid(id) {
|
|
378
|
+
return id.split(':')[1];
|
|
379
|
+
}
|
|
380
|
+
isId(id) {
|
|
381
|
+
return id.startsWith(`${this.prefix}:`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function createEntityType(name, options) {
|
|
385
|
+
const { parentType, prefix } = options ?? {};
|
|
386
|
+
return new DefinitionEntityType(name, prefix, parentType);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const zodPluginSymbol = Symbol('zod-plugin');
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Zod Plugin Wrapper
|
|
393
|
+
*
|
|
394
|
+
* Used for initializing the zod parsing with plugins
|
|
395
|
+
*/
|
|
396
|
+
const {ZodType: ZodType$1} = await importShared('zod');
|
|
397
|
+
class ZodPluginWrapper extends ZodType$1 {
|
|
398
|
+
_parse(input) {
|
|
399
|
+
// run builder
|
|
400
|
+
const pluginContext = {
|
|
401
|
+
pluginStore: this._def.pluginStore,
|
|
402
|
+
};
|
|
403
|
+
return this._def.innerType._parse({
|
|
404
|
+
...input,
|
|
405
|
+
parent: {
|
|
406
|
+
...input.parent,
|
|
407
|
+
common: {
|
|
408
|
+
...input.parent.common,
|
|
409
|
+
[zodPluginSymbol]: pluginContext,
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
get pluginStore() {
|
|
415
|
+
return this._def.pluginStore;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
Object.defineProperty(ZodPluginWrapper, "create", {
|
|
419
|
+
enumerable: true,
|
|
420
|
+
configurable: true,
|
|
421
|
+
writable: true,
|
|
422
|
+
value: (type, pluginStore) => new ZodPluginWrapper({
|
|
423
|
+
innerType: type,
|
|
424
|
+
pluginStore,
|
|
425
|
+
})
|
|
426
|
+
});
|
|
427
|
+
function zPluginWrapper(type, pluginStore) {
|
|
428
|
+
return ZodPluginWrapper.create(type, pluginStore);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function isDeepKey(key) {
|
|
432
|
+
switch (typeof key) {
|
|
433
|
+
case 'number':
|
|
434
|
+
case 'symbol': {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
case 'string': {
|
|
438
|
+
return key.includes('.') || key.includes('[') || key.includes(']');
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function toKey(value) {
|
|
444
|
+
if (Object.is(value, -0)) {
|
|
445
|
+
return '-0';
|
|
446
|
+
}
|
|
447
|
+
return value.toString();
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function toPath(deepKey) {
|
|
451
|
+
const result = [];
|
|
452
|
+
const length = deepKey.length;
|
|
453
|
+
if (length === 0) {
|
|
454
|
+
return result;
|
|
455
|
+
}
|
|
456
|
+
let index = 0;
|
|
457
|
+
let key = '';
|
|
458
|
+
let quoteChar = '';
|
|
459
|
+
let bracket = false;
|
|
460
|
+
if (deepKey.charCodeAt(0) === 46) {
|
|
461
|
+
result.push('');
|
|
462
|
+
index++;
|
|
463
|
+
}
|
|
464
|
+
while (index < length) {
|
|
465
|
+
const char = deepKey[index];
|
|
466
|
+
if (quoteChar) {
|
|
467
|
+
if (char === '\\' && index + 1 < length) {
|
|
468
|
+
index++;
|
|
469
|
+
key += deepKey[index];
|
|
470
|
+
}
|
|
471
|
+
else if (char === quoteChar) {
|
|
472
|
+
quoteChar = '';
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
key += char;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else if (bracket) {
|
|
479
|
+
if (char === '"' || char === "'") {
|
|
480
|
+
quoteChar = char;
|
|
481
|
+
}
|
|
482
|
+
else if (char === ']') {
|
|
483
|
+
bracket = false;
|
|
484
|
+
result.push(key);
|
|
485
|
+
key = '';
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
key += char;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
if (char === '[') {
|
|
493
|
+
bracket = true;
|
|
494
|
+
if (key) {
|
|
495
|
+
result.push(key);
|
|
496
|
+
key = '';
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
else if (char === '.') {
|
|
500
|
+
if (key) {
|
|
501
|
+
result.push(key);
|
|
502
|
+
key = '';
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
key += char;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
index++;
|
|
510
|
+
}
|
|
511
|
+
if (key) {
|
|
512
|
+
result.push(key);
|
|
513
|
+
}
|
|
514
|
+
return result;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function get(object, path, defaultValue) {
|
|
518
|
+
if (object == null) {
|
|
519
|
+
return defaultValue;
|
|
520
|
+
}
|
|
521
|
+
switch (typeof path) {
|
|
522
|
+
case 'string': {
|
|
523
|
+
const result = object[path];
|
|
524
|
+
if (result === undefined) {
|
|
525
|
+
if (isDeepKey(path)) {
|
|
526
|
+
return get(object, toPath(path), defaultValue);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
return defaultValue;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return result;
|
|
533
|
+
}
|
|
534
|
+
case 'number':
|
|
535
|
+
case 'symbol': {
|
|
536
|
+
if (typeof path === 'number') {
|
|
537
|
+
path = toKey(path);
|
|
538
|
+
}
|
|
539
|
+
const result = object[path];
|
|
540
|
+
if (result === undefined) {
|
|
541
|
+
return defaultValue;
|
|
542
|
+
}
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
default: {
|
|
546
|
+
if (Array.isArray(path)) {
|
|
547
|
+
return getWithPath(object, path, defaultValue);
|
|
548
|
+
}
|
|
549
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
550
|
+
path = '-0';
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
path = String(path);
|
|
554
|
+
}
|
|
555
|
+
const result = object[path];
|
|
556
|
+
if (result === undefined) {
|
|
557
|
+
return defaultValue;
|
|
558
|
+
}
|
|
559
|
+
return result;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
function getWithPath(object, path, defaultValue) {
|
|
564
|
+
if (path.length === 0) {
|
|
565
|
+
return defaultValue;
|
|
566
|
+
}
|
|
567
|
+
let current = object;
|
|
568
|
+
for (let index = 0; index < path.length; index++) {
|
|
569
|
+
if (current == null) {
|
|
570
|
+
return defaultValue;
|
|
571
|
+
}
|
|
572
|
+
current = current[path[index]];
|
|
573
|
+
}
|
|
574
|
+
if (current === undefined) {
|
|
575
|
+
return defaultValue;
|
|
576
|
+
}
|
|
577
|
+
return current;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
|
|
581
|
+
function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
|
|
582
|
+
switch (typeof value) {
|
|
583
|
+
case 'number': {
|
|
584
|
+
return Number.isInteger(value) && value >= 0 && value < length;
|
|
585
|
+
}
|
|
586
|
+
case 'symbol': {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
case 'string': {
|
|
590
|
+
return IS_UNSIGNED_INTEGER.test(value);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function set(obj, path, value) {
|
|
596
|
+
const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
|
|
597
|
+
let current = obj;
|
|
598
|
+
for (let i = 0; i < resolvedPath.length - 1; i++) {
|
|
599
|
+
const key = resolvedPath[i];
|
|
600
|
+
const nextKey = resolvedPath[i + 1];
|
|
601
|
+
if (current[key] == null) {
|
|
602
|
+
current[key] = isIndex(nextKey) ? [] : {};
|
|
603
|
+
}
|
|
604
|
+
current = current[key];
|
|
605
|
+
}
|
|
606
|
+
const lastKey = resolvedPath[resolvedPath.length - 1];
|
|
607
|
+
current[lastKey] = value;
|
|
608
|
+
return obj;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const {z: z$1,ZodType} = await importShared('zod');
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Zod reference ID schema: a string with a minimum length of 1.
|
|
615
|
+
*/
|
|
616
|
+
const zRefId = z$1.string().min(1);
|
|
617
|
+
/**
|
|
618
|
+
* Determines whether the given object is a Promise.
|
|
619
|
+
* @param object - The value to test.
|
|
620
|
+
* @returns True if the value is a Promise, false otherwise.
|
|
621
|
+
*/
|
|
622
|
+
function isPromise(object) {
|
|
623
|
+
return object instanceof Promise;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Creates a definition entity name resolver.
|
|
627
|
+
* @param entityNameResolver - The entity name resolver.
|
|
628
|
+
* @returns The definition entity name resolver.
|
|
629
|
+
*/
|
|
630
|
+
function createDefinitionEntityNameResolver(entityNameResolver) {
|
|
631
|
+
return entityNameResolver;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* ZodRefBuilder is responsible for constructing reference paths, and registering
|
|
635
|
+
* references and entities as defined in a Zod schema.
|
|
636
|
+
*
|
|
637
|
+
* The builder uses a prefix (usually the current parsing path) and context (a
|
|
638
|
+
* shared map for resolving relative references) to build complete reference paths.
|
|
639
|
+
*
|
|
640
|
+
* @template TInput - The type of the input data being parsed.
|
|
641
|
+
*/
|
|
642
|
+
class ZodRefBuilder {
|
|
643
|
+
/**
|
|
644
|
+
* Creates a new builder instance.
|
|
645
|
+
* @param pathPrefix - The starting path for all references.
|
|
646
|
+
* @param context - Shared context including a path map and deserialize flag.
|
|
647
|
+
* @param data - The data being parsed.
|
|
648
|
+
*/
|
|
649
|
+
constructor(pathPrefix, context, data) {
|
|
650
|
+
Object.defineProperty(this, "references", {
|
|
651
|
+
enumerable: true,
|
|
652
|
+
configurable: true,
|
|
653
|
+
writable: true,
|
|
654
|
+
value: void 0
|
|
655
|
+
});
|
|
656
|
+
Object.defineProperty(this, "entitiesWithNameResolver", {
|
|
657
|
+
enumerable: true,
|
|
658
|
+
configurable: true,
|
|
659
|
+
writable: true,
|
|
660
|
+
value: void 0
|
|
661
|
+
});
|
|
662
|
+
Object.defineProperty(this, "pathPrefix", {
|
|
663
|
+
enumerable: true,
|
|
664
|
+
configurable: true,
|
|
665
|
+
writable: true,
|
|
666
|
+
value: void 0
|
|
667
|
+
});
|
|
668
|
+
Object.defineProperty(this, "context", {
|
|
669
|
+
enumerable: true,
|
|
670
|
+
configurable: true,
|
|
671
|
+
writable: true,
|
|
672
|
+
value: void 0
|
|
673
|
+
});
|
|
674
|
+
Object.defineProperty(this, "pathMap", {
|
|
675
|
+
enumerable: true,
|
|
676
|
+
configurable: true,
|
|
677
|
+
writable: true,
|
|
678
|
+
value: void 0
|
|
679
|
+
});
|
|
680
|
+
Object.defineProperty(this, "data", {
|
|
681
|
+
enumerable: true,
|
|
682
|
+
configurable: true,
|
|
683
|
+
writable: true,
|
|
684
|
+
value: void 0
|
|
685
|
+
});
|
|
686
|
+
this.references = [];
|
|
687
|
+
this.entitiesWithNameResolver = [];
|
|
688
|
+
this.pathPrefix = pathPrefix;
|
|
689
|
+
this.context = context;
|
|
690
|
+
this.pathMap = new Map();
|
|
691
|
+
this.data = data;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Converts a dot-separated string path into an array of keys.
|
|
695
|
+
* @param path - A string (e.g. "a.b.0.c") representing the path.
|
|
696
|
+
* @returns An array of keys (numbers for numeric strings, otherwise strings).
|
|
697
|
+
*/
|
|
698
|
+
_constructPathWithoutPrefix(path) {
|
|
699
|
+
if (!path)
|
|
700
|
+
return [];
|
|
701
|
+
const pathComponents = path
|
|
702
|
+
.split('.')
|
|
703
|
+
.map((key) => (/^[0-9]+$/.test(key) ? Number.parseInt(key, 10) : key));
|
|
704
|
+
return pathComponents;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Prepends the builder's path prefix to the provided path.
|
|
708
|
+
* @param path - The dot-separated path string.
|
|
709
|
+
* @returns The complete reference path as an array.
|
|
710
|
+
*/
|
|
711
|
+
_constructPath(path) {
|
|
712
|
+
if (!path)
|
|
713
|
+
return this.pathPrefix;
|
|
714
|
+
return [...this.pathPrefix, ...this._constructPathWithoutPrefix(path)];
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Constructs a reference path that may be defined directly as a string or indirectly
|
|
718
|
+
* via a context object. If a context object is provided, the function looks up the
|
|
719
|
+
* actual path from the builder's context.
|
|
720
|
+
*
|
|
721
|
+
* @param path - Either a dot-separated string path or an object with a context key.
|
|
722
|
+
* @param expectedEntityType - The entity type expected for this context.
|
|
723
|
+
* @returns The resolved reference path.
|
|
724
|
+
* @throws If the context cannot be found or its type does not match.
|
|
725
|
+
*/
|
|
726
|
+
_constructPathWithContext(path, expectedEntityType) {
|
|
727
|
+
if (typeof path === 'string') {
|
|
728
|
+
return this._constructPath(path);
|
|
729
|
+
}
|
|
730
|
+
// Lookup the context for the given key.
|
|
731
|
+
const pathContext = this.context.pathMap.get(path.context);
|
|
732
|
+
if (!pathContext) {
|
|
733
|
+
throw new Error(`Could not find context for ${path.context} from ${this.pathPrefix.join('.')}`);
|
|
734
|
+
}
|
|
735
|
+
if (pathContext.type !== expectedEntityType) {
|
|
736
|
+
throw new Error(`Attempted to retrieve context for ${path.context} from ${this.pathPrefix.join('.')} expecting ${expectedEntityType.name}, but found ${pathContext.type.name}`);
|
|
737
|
+
}
|
|
738
|
+
return pathContext.path;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Registers a reference based on the provided input definition.
|
|
742
|
+
*
|
|
743
|
+
* Flow:
|
|
744
|
+
* 1. Validate that the parent path is provided if required (and vice versa).
|
|
745
|
+
* 2. Compute the reference path; if the path is empty, use the entire data.
|
|
746
|
+
* 3. If the referenced value is null or undefined, skip adding the reference.
|
|
747
|
+
* 4. Otherwise, add the reference and, if requested, register its context.
|
|
748
|
+
*
|
|
749
|
+
* @param reference - The reference definition.
|
|
750
|
+
* @throws If parent path usage is incorrect.
|
|
751
|
+
*/
|
|
752
|
+
addReference(reference) {
|
|
753
|
+
if (!reference.type.parentType && reference.parentPath) {
|
|
754
|
+
throw new Error(`Parent path does nothing since reference does not have parent`);
|
|
755
|
+
}
|
|
756
|
+
if (reference.type.parentType && !reference.parentPath) {
|
|
757
|
+
throw new Error(`Parent path required if reference type has parent type`);
|
|
758
|
+
}
|
|
759
|
+
// Compute the path without prefix once.
|
|
760
|
+
const refPathWithoutPrefix = this._constructPathWithoutPrefix(reference.path);
|
|
761
|
+
// If the path is empty, use the entire data; otherwise, retrieve the value.
|
|
762
|
+
const refValue = refPathWithoutPrefix.length === 0
|
|
763
|
+
? this.data
|
|
764
|
+
: get(this.data, refPathWithoutPrefix);
|
|
765
|
+
if (refValue === undefined || refValue === null)
|
|
766
|
+
return;
|
|
767
|
+
const fullPath = this._constructPath(reference.path);
|
|
768
|
+
this.references.push({
|
|
769
|
+
type: reference.type,
|
|
770
|
+
path: fullPath,
|
|
771
|
+
parentPath: reference.parentPath &&
|
|
772
|
+
reference.type.parentType &&
|
|
773
|
+
this._constructPathWithContext(reference.parentPath, reference.type.parentType),
|
|
774
|
+
onDelete: reference.onDelete,
|
|
775
|
+
});
|
|
776
|
+
// Optionally, add this path to the shared context.
|
|
777
|
+
if (reference.addContext) {
|
|
778
|
+
this._addPathToContext(fullPath, reference.type, reference.addContext);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Registers an entity based on the provided definition.
|
|
783
|
+
*
|
|
784
|
+
* Flow:
|
|
785
|
+
* 1. Validate that not both a name and a name reference path are provided.
|
|
786
|
+
* 2. Compute the full entity path.
|
|
787
|
+
* 3. Resolve the entity ID:
|
|
788
|
+
* - Use the provided idPath if available; otherwise, default to appending 'id'
|
|
789
|
+
* to the entity path.
|
|
790
|
+
* - If no id is found, generate a new one.
|
|
791
|
+
* 4. Resolve the entity name:
|
|
792
|
+
* - Use the provided resolveName if available; otherwise, default to using the
|
|
793
|
+
* name path.
|
|
794
|
+
* 5. Register the entity in either the direct entities list or the name-ref list.
|
|
795
|
+
* 6. Optionally, add the entity’s id path to the shared context.
|
|
796
|
+
*
|
|
797
|
+
* @param entity - The entity definition.
|
|
798
|
+
* @throws If both name and nameRefPath are provided or if no name is resolved.
|
|
799
|
+
*/
|
|
800
|
+
addEntity(entity) {
|
|
801
|
+
// Build the full path for the entity.
|
|
802
|
+
const path = this._constructPath(entity.path);
|
|
803
|
+
// Resolve the id path: if provided use it; otherwise, assume the id is at "entity.path.id"
|
|
804
|
+
const idPath = entity.idPath
|
|
805
|
+
? this._constructPathWithoutPrefix(entity.idPath)
|
|
806
|
+
: [...this._constructPathWithoutPrefix(entity.path), 'id'];
|
|
807
|
+
// TODO [>=0.9.16] Remove the fallback to generateNewId once a new version is released and manual setter
|
|
808
|
+
const id = get(this.data, idPath) ??
|
|
809
|
+
entity.type.generateNewId();
|
|
810
|
+
if (!get(this.data, idPath)) {
|
|
811
|
+
set(this.data, idPath, id);
|
|
812
|
+
}
|
|
813
|
+
if (!entity.type.isId(id)) {
|
|
814
|
+
throw new Error(`Invalid id: ${id} for entity ${entity.type.name}`);
|
|
815
|
+
}
|
|
816
|
+
// Resolve the name: if getNameResolver is provided, use it to build the name resolver; otherwise,
|
|
817
|
+
// use the default name resolver.
|
|
818
|
+
const getNameResolver = entity.getNameResolver ?? ((value) => get(value, 'name'));
|
|
819
|
+
const nameResolver = getNameResolver(this.data);
|
|
820
|
+
// Base entity definition shared between regular entities and those with a name reference.
|
|
821
|
+
const entityBase = {
|
|
822
|
+
id,
|
|
823
|
+
type: entity.type,
|
|
824
|
+
path,
|
|
825
|
+
idPath: [...this.pathPrefix, ...idPath],
|
|
826
|
+
parentPath: entity.parentPath &&
|
|
827
|
+
entity.type.parentType &&
|
|
828
|
+
this._constructPathWithContext(entity.parentPath, entity.type.parentType),
|
|
829
|
+
};
|
|
830
|
+
this.entitiesWithNameResolver.push({
|
|
831
|
+
...entityBase,
|
|
832
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- needed to allow more specific generic typed to be put in here
|
|
833
|
+
nameResolver: typeof nameResolver === 'string'
|
|
834
|
+
? { resolveName: () => nameResolver }
|
|
835
|
+
: nameResolver,
|
|
836
|
+
});
|
|
837
|
+
// Optionally add the id path to the context.
|
|
838
|
+
if (entity.addContext) {
|
|
839
|
+
this._addPathToContext([...this.pathPrefix, ...idPath], entity.type, entity.addContext);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Registers a given path into the builder's context map.
|
|
844
|
+
* @param path - The full reference path.
|
|
845
|
+
* @param type - The entity type associated with the path.
|
|
846
|
+
* @param context - A unique key to identify this context.
|
|
847
|
+
* @throws If the context key is already registered.
|
|
848
|
+
*/
|
|
849
|
+
_addPathToContext(path, type, context) {
|
|
850
|
+
if (this.pathMap.has(context)) {
|
|
851
|
+
throw new Error(`Context path already defined for ${context} at ${this.pathPrefix.join('.')}`);
|
|
852
|
+
}
|
|
853
|
+
this.pathMap.set(context, { path, type });
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Convenience method that builds a full path from a dot-separated string and
|
|
857
|
+
* adds it to the context.
|
|
858
|
+
* @param path - The dot-separated string path.
|
|
859
|
+
* @param type - The entity type.
|
|
860
|
+
* @param context - The context key.
|
|
861
|
+
*/
|
|
862
|
+
addPathToContext(path, type, context) {
|
|
863
|
+
this._addPathToContext(this._constructPath(path), type, context);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Unique symbol used to store ZodRef context in the parent’s common context.
|
|
868
|
+
*/
|
|
869
|
+
const zodRefSymbol = Symbol('zod-ref');
|
|
870
|
+
/**
|
|
871
|
+
* ZodRef wraps an inner Zod type and enhances it with the ability to register
|
|
872
|
+
* and process entity references. During parsing, it delegates to a builder (if present)
|
|
873
|
+
* to collect references and entities before delegating to the inner type.
|
|
874
|
+
*
|
|
875
|
+
* @template T - The inner Zod type.
|
|
876
|
+
*/
|
|
877
|
+
class ZodRef extends ZodType {
|
|
878
|
+
/**
|
|
879
|
+
* The core parse method that:
|
|
880
|
+
* 1. Retrieves (or creates) the builder context from the parent.
|
|
881
|
+
* 2. Runs the builder function (if present) to register references/entities.
|
|
882
|
+
* 3. Delegates parsing to the inner type.
|
|
883
|
+
* 4. Transforms the output to replace entity id placeholders with generated ids.
|
|
884
|
+
*
|
|
885
|
+
* @param input - The Zod parse input.
|
|
886
|
+
* @returns The parse result.
|
|
887
|
+
*/
|
|
888
|
+
_parse(input) {
|
|
889
|
+
const context = input.parent.common;
|
|
890
|
+
// If no builder context or builder function exists, simply parse using the inner type.
|
|
891
|
+
const zodRefContext = context[zodRefSymbol];
|
|
892
|
+
if (!zodRefContext || !this._def.builder) {
|
|
893
|
+
return this._def.innerType._parse(input);
|
|
894
|
+
}
|
|
895
|
+
// Create a new builder instance for the current parsing context.
|
|
896
|
+
const builder = new ZodRefBuilder(input.path, zodRefContext.context, input.data);
|
|
897
|
+
// Execute the builder function to register references/entities.
|
|
898
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
899
|
+
this._def.builder(builder, input.data);
|
|
900
|
+
zodRefContext.references.push(...builder.references);
|
|
901
|
+
zodRefContext.entitiesWithNameResolver.push(...builder.entitiesWithNameResolver);
|
|
902
|
+
// Re-parse using the inner type but merge the updated context.
|
|
903
|
+
const parseOutput = this._def.innerType._parse({
|
|
904
|
+
...input,
|
|
905
|
+
path: input.path,
|
|
906
|
+
parent: {
|
|
907
|
+
...input.parent,
|
|
908
|
+
common: {
|
|
909
|
+
...input.parent.common,
|
|
910
|
+
[zodRefSymbol]: {
|
|
911
|
+
...zodRefContext,
|
|
912
|
+
context: {
|
|
913
|
+
...zodRefContext.context,
|
|
914
|
+
// Merge new context entries from the builder.
|
|
915
|
+
pathMap: new Map([
|
|
916
|
+
...zodRefContext.context.pathMap,
|
|
917
|
+
...builder.pathMap,
|
|
918
|
+
]),
|
|
919
|
+
},
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
});
|
|
924
|
+
/**
|
|
925
|
+
* Transforms the output of the inner parse by iterating through all registered
|
|
926
|
+
* entities and assigning the id to the corresponding path in the output in case
|
|
927
|
+
* it was generated by the builder.
|
|
928
|
+
*
|
|
929
|
+
* @param output - The result from the inner parse.
|
|
930
|
+
* @returns The transformed parse output.
|
|
931
|
+
*/
|
|
932
|
+
function transformParseOutput(output) {
|
|
933
|
+
if (output.status === 'aborted')
|
|
934
|
+
return output;
|
|
935
|
+
// For each entity, assign the id to the corresponding path in the output
|
|
936
|
+
// in the event that it was generated by the builder.
|
|
937
|
+
for (const entity of builder.entitiesWithNameResolver) {
|
|
938
|
+
set(output.value, entity.idPath.slice(input.path.length), entity.id);
|
|
939
|
+
}
|
|
940
|
+
return output;
|
|
941
|
+
}
|
|
942
|
+
// If the parse result is a Promise, attach the transformation asynchronously.
|
|
943
|
+
if (isPromise(parseOutput)) {
|
|
944
|
+
return parseOutput.then(transformParseOutput);
|
|
945
|
+
}
|
|
946
|
+
return transformParseOutput(parseOutput);
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Returns the inner Zod type.
|
|
950
|
+
* @returns The wrapped inner Zod type.
|
|
951
|
+
*/
|
|
952
|
+
innerType() {
|
|
953
|
+
return this._def.innerType;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Adds an entity registration to the current ZodRef.
|
|
957
|
+
*
|
|
958
|
+
* @param entity - Either an entity definition or a function that returns one.
|
|
959
|
+
* @returns A new ZodRef instance with the entity registration added.
|
|
960
|
+
*/
|
|
961
|
+
addEntity(entity) {
|
|
962
|
+
return ZodRef.create(this, (builder, data) => {
|
|
963
|
+
builder.addEntity(typeof entity === 'function' ? entity(data) : entity);
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Adds a reference registration to the current ZodRef.
|
|
968
|
+
*
|
|
969
|
+
* @param reference - Either a reference definition or a function that returns one.
|
|
970
|
+
* @returns A new ZodRef instance with the reference registration added.
|
|
971
|
+
*/
|
|
972
|
+
addReference(reference) {
|
|
973
|
+
return ZodRef.create(this, (builder, data) => {
|
|
974
|
+
builder.addReference(typeof reference === 'function' ? reference(data) : reference);
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Applies a custom builder function to the ZodRef.
|
|
979
|
+
* @param builder - The builder function that registers additional references/entities.
|
|
980
|
+
* @returns A new ZodRef instance with the builder applied.
|
|
981
|
+
*/
|
|
982
|
+
refBuilder(builder) {
|
|
983
|
+
return ZodRef.create(this, builder);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Creates a new ZodRef instance wrapping a given Zod type with an optional builder.
|
|
988
|
+
* @param type - The inner Zod type.
|
|
989
|
+
* @param builder - Optional builder function to register references/entities.
|
|
990
|
+
* @returns A new ZodRef instance.
|
|
991
|
+
*/
|
|
992
|
+
Object.defineProperty(ZodRef, "create", {
|
|
993
|
+
enumerable: true,
|
|
994
|
+
configurable: true,
|
|
995
|
+
writable: true,
|
|
996
|
+
value: (type, builder) => new ZodRef({
|
|
997
|
+
innerType: type,
|
|
998
|
+
builder,
|
|
999
|
+
})
|
|
1000
|
+
});
|
|
1001
|
+
/**
|
|
1002
|
+
* Convenience function for creating a ZodRef using a schema and an optional builder.
|
|
1003
|
+
* @param schema - The base Zod schema.
|
|
1004
|
+
* @param builder - Optional builder function.
|
|
1005
|
+
* @returns A new ZodRef instance.
|
|
1006
|
+
*/
|
|
1007
|
+
function zRefBuilder(schema, builder) {
|
|
1008
|
+
return ZodRef.create(schema, builder);
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Convenience function for creating a ZodRef with a reference added.
|
|
1012
|
+
* @param schema - The base Zod schema.
|
|
1013
|
+
* @param reference - Either a reference definition or a function returning one.
|
|
1014
|
+
* @returns A new ZodRef instance with the reference registration.
|
|
1015
|
+
*/
|
|
1016
|
+
function zRef(schema, reference) {
|
|
1017
|
+
return ZodRef.create(schema).addReference(reference);
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Convenience function for creating a ZodRef that registers an entity.
|
|
1021
|
+
* This function also sets the id key on the schema using zRefId.
|
|
1022
|
+
*
|
|
1023
|
+
* @template TObject - The Zod object type.
|
|
1024
|
+
* @template TEntityType - The entity type.
|
|
1025
|
+
* @template TPath - The path type.
|
|
1026
|
+
* @param schema - The base Zod object schema.
|
|
1027
|
+
* @param entity - Either an entity definition or a function returning one.
|
|
1028
|
+
* @returns A new ZodRef instance with the entity registration.
|
|
1029
|
+
*/
|
|
1030
|
+
function zEnt(schema, entity) {
|
|
1031
|
+
// Set the "id" key on the schema using zRefId and then register the entity.
|
|
1032
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-explicit-any
|
|
1033
|
+
return ZodRef.create(schema.setKey('id', zRefId)).addEntity(entity);
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* ZodRefWrapper is used for initializing parsing that collects references and entities.
|
|
1037
|
+
*
|
|
1038
|
+
* @template T - The inner Zod type.
|
|
1039
|
+
*/
|
|
1040
|
+
class ZodRefWrapper extends ZodType {
|
|
1041
|
+
/**
|
|
1042
|
+
* Core parse method that:
|
|
1043
|
+
* 1. Initializes a fresh reference context.
|
|
1044
|
+
* 2. Parses using the inner type while injecting the context.
|
|
1045
|
+
* 3. Returns a payload containing the parsed data, along with references and entities.
|
|
1046
|
+
*
|
|
1047
|
+
* @param input - The parse input.
|
|
1048
|
+
* @returns The parsed payload.
|
|
1049
|
+
*/
|
|
1050
|
+
_parse(input) {
|
|
1051
|
+
// Initialize the reference context.
|
|
1052
|
+
const refContext = {
|
|
1053
|
+
context: {
|
|
1054
|
+
pathMap: new Map(),
|
|
1055
|
+
},
|
|
1056
|
+
references: [],
|
|
1057
|
+
entitiesWithNameResolver: [],
|
|
1058
|
+
};
|
|
1059
|
+
// Inject the refContext into the parent's common context and parse the inner type.
|
|
1060
|
+
const parseOutput = this._def.innerType._parse({
|
|
1061
|
+
...input,
|
|
1062
|
+
parent: {
|
|
1063
|
+
...input.parent,
|
|
1064
|
+
common: {
|
|
1065
|
+
...input.parent.common,
|
|
1066
|
+
[zodRefSymbol]: refContext,
|
|
1067
|
+
},
|
|
1068
|
+
},
|
|
1069
|
+
});
|
|
1070
|
+
function transformParseOutput(output) {
|
|
1071
|
+
if (output.status === 'aborted')
|
|
1072
|
+
return output;
|
|
1073
|
+
return {
|
|
1074
|
+
...output,
|
|
1075
|
+
value: {
|
|
1076
|
+
data: output.value,
|
|
1077
|
+
entitiesWithNameResolver: refContext.entitiesWithNameResolver,
|
|
1078
|
+
references: refContext.references,
|
|
1079
|
+
},
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
if (isPromise(parseOutput)) {
|
|
1083
|
+
return parseOutput.then(transformParseOutput);
|
|
1084
|
+
}
|
|
1085
|
+
return transformParseOutput(parseOutput);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Creates a new ZodRefWrapper instance.
|
|
1090
|
+
* @param type - The inner Zod type.
|
|
1091
|
+
* @param options - Options for the ZodRefWrapper.
|
|
1092
|
+
* @param options.skipReferenceNameResolution - Flag to skip resolving references to names (serialized definitions use resolved name references).
|
|
1093
|
+
* @param options.allowInvalidReferences - Flag to allow invalid references (used for testing deletes).
|
|
1094
|
+
* @returns A new instance of ZodRefWrapper.
|
|
1095
|
+
*/
|
|
1096
|
+
Object.defineProperty(ZodRefWrapper, "create", {
|
|
1097
|
+
enumerable: true,
|
|
1098
|
+
configurable: true,
|
|
1099
|
+
writable: true,
|
|
1100
|
+
value: (type) => new ZodRefWrapper({
|
|
1101
|
+
innerType: type,
|
|
1102
|
+
})
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
const {z} = await importShared('zod');
|
|
1106
|
+
const featureEntityType = createEntityType('feature');
|
|
1107
|
+
const featureNameSchema = CASE_VALIDATORS.KEBAB_CASE;
|
|
1108
|
+
const featureSchema = zEnt(z.object({
|
|
1109
|
+
name: z
|
|
1110
|
+
.string()
|
|
1111
|
+
.min(1)
|
|
1112
|
+
.refine((name) => name
|
|
1113
|
+
.split('/')
|
|
1114
|
+
.every((part) => featureNameSchema.safeParse(part).success), {
|
|
1115
|
+
message: 'Feature name must be lowercase and contain only letters, numbers, and dashes',
|
|
1116
|
+
}),
|
|
1117
|
+
parentRef: zRef(z.string().nullish(), {
|
|
1118
|
+
type: featureEntityType,
|
|
1119
|
+
onDelete: 'DELETE_PARENT',
|
|
1120
|
+
}),
|
|
1121
|
+
}), { type: featureEntityType });
|
|
1122
|
+
const featuresSchema = z.array(featureSchema).default([]);
|
|
1123
|
+
|
|
1124
|
+
function getRootFeatures(projectDefinition) {
|
|
1125
|
+
return projectDefinition.features.filter((f) => !f.parentRef);
|
|
1126
|
+
}
|
|
1127
|
+
function getFeatureById(projectDefinition, featureId) {
|
|
1128
|
+
return projectDefinition.features.find((f) => f.id === featureId);
|
|
1129
|
+
}
|
|
1130
|
+
function getFeatureByIdOrThrow(projectDefinition, featureId) {
|
|
1131
|
+
const feature = getFeatureById(projectDefinition, featureId);
|
|
1132
|
+
if (!feature) {
|
|
1133
|
+
throw new Error(`Could not find feature with ID ${featureId}`);
|
|
1134
|
+
}
|
|
1135
|
+
return feature;
|
|
1136
|
+
}
|
|
1137
|
+
function getFeatureChildren(projectDefinition, featureId) {
|
|
1138
|
+
return projectDefinition.features.filter((f) => f.parentRef === featureId);
|
|
1139
|
+
}
|
|
1140
|
+
function getFeatureName(featureConfig) {
|
|
1141
|
+
return featureConfig.name.split('/').pop() ?? '';
|
|
1142
|
+
}
|
|
1143
|
+
function getFeatureNameById(projectDefinition, featureId) {
|
|
1144
|
+
const feature = getFeatureByIdOrThrow(projectDefinition, featureId);
|
|
1145
|
+
return getFeatureName(feature);
|
|
1146
|
+
}
|
|
1147
|
+
function getFeaturePathById(projectDefinition, featureId) {
|
|
1148
|
+
const feature = getFeatureByIdOrThrow(projectDefinition, featureId);
|
|
1149
|
+
return feature.name;
|
|
1150
|
+
}
|
|
1151
|
+
function validateFeatureName(name) {
|
|
1152
|
+
const nameParts = name.split('/');
|
|
1153
|
+
return nameParts.every((part) => featureNameSchema.safeParse(part).success);
|
|
1154
|
+
}
|
|
1155
|
+
function ensureFeatureByNameRecursively(projectDefinition, nameOrId) {
|
|
1156
|
+
if (featureEntityType.isId(nameOrId)) {
|
|
1157
|
+
return nameOrId;
|
|
1158
|
+
}
|
|
1159
|
+
const nameParts = nameOrId.split('/');
|
|
1160
|
+
let lastName = '';
|
|
1161
|
+
let parentRef = null;
|
|
1162
|
+
for (const part of nameParts) {
|
|
1163
|
+
const feature = projectDefinition.features.find((f) => f.name === part && f.parentRef === parentRef);
|
|
1164
|
+
const name = [lastName, part].filter(Boolean).join('/');
|
|
1165
|
+
if (feature) {
|
|
1166
|
+
parentRef = feature.id;
|
|
1167
|
+
}
|
|
1168
|
+
else {
|
|
1169
|
+
const newFeature = {
|
|
1170
|
+
id: featureEntityType.generateNewId(),
|
|
1171
|
+
name,
|
|
1172
|
+
parentRef,
|
|
1173
|
+
};
|
|
1174
|
+
projectDefinition.features.push(newFeature);
|
|
1175
|
+
parentRef = newFeature.id;
|
|
1176
|
+
}
|
|
1177
|
+
lastName = name;
|
|
1178
|
+
}
|
|
1179
|
+
if (!parentRef) {
|
|
1180
|
+
throw new Error('Failed to create feature');
|
|
1181
|
+
}
|
|
1182
|
+
return parentRef;
|
|
1183
|
+
}
|
|
1184
|
+
function getFeatureByName(projectDefinition, name) {
|
|
1185
|
+
return projectDefinition.features.find((f) => f.name === name);
|
|
1186
|
+
}
|
|
1187
|
+
function getFeatureIdByNameOrDefault(projectDefinition, name) {
|
|
1188
|
+
return getFeatureByName(projectDefinition, name)?.id ?? name;
|
|
1189
|
+
}
|
|
1190
|
+
const FeatureUtils = {
|
|
1191
|
+
getRootFeatures,
|
|
1192
|
+
getFeatureById,
|
|
1193
|
+
getFeatureByIdOrThrow,
|
|
1194
|
+
getFeatureChildren,
|
|
1195
|
+
getFeatureName,
|
|
1196
|
+
getFeatureNameById,
|
|
1197
|
+
getFeaturePathById,
|
|
1198
|
+
validateFeatureName,
|
|
1199
|
+
ensureFeatureByNameRecursively,
|
|
1200
|
+
getFeatureByName,
|
|
1201
|
+
getFeatureIdByNameOrDefault,
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
function byId(projectDefinition, id) {
|
|
1205
|
+
return projectDefinition.models.find((m) => m.id === id);
|
|
1206
|
+
}
|
|
1207
|
+
function byIdOrThrow(projectDefinition, id) {
|
|
1208
|
+
const model = byId(projectDefinition, id);
|
|
1209
|
+
if (!model) {
|
|
1210
|
+
throw new Error(`Could not find model with ID ${id}`);
|
|
1211
|
+
}
|
|
1212
|
+
return model;
|
|
1213
|
+
}
|
|
1214
|
+
function getScalarFieldById(model, id) {
|
|
1215
|
+
const field = model.model.fields.find((f) => f.id === id);
|
|
1216
|
+
if (!field) {
|
|
1217
|
+
throw new Error(`Could not find field with ID ${id}`);
|
|
1218
|
+
}
|
|
1219
|
+
return field;
|
|
1220
|
+
}
|
|
1221
|
+
function getRelationsToModel(projectDefinition, modelId) {
|
|
1222
|
+
return projectDefinition.models.flatMap((m) => m.model.relations
|
|
1223
|
+
?.filter((r) => r.modelRef === modelId)
|
|
1224
|
+
.map((r) => ({ model: m, relation: r })) ?? []);
|
|
1225
|
+
}
|
|
1226
|
+
function getModelsForFeature(projectDefinition, featureId) {
|
|
1227
|
+
return projectDefinition.models.filter((m) => m.featureRef === featureId);
|
|
1228
|
+
}
|
|
1229
|
+
function getModelIdFields(model) {
|
|
1230
|
+
return model.model.primaryKeyFieldRefs;
|
|
1231
|
+
}
|
|
1232
|
+
function hasService(model) {
|
|
1233
|
+
return (!!model.service.create.enabled ||
|
|
1234
|
+
!!model.service.update.enabled ||
|
|
1235
|
+
!!model.service.delete.enabled ||
|
|
1236
|
+
model.service.transformers.length > 0);
|
|
1237
|
+
}
|
|
1238
|
+
function validateModelName(name) {
|
|
1239
|
+
return PASCAL_CASE_REGEX.test(name);
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Returns the ID of a model by name, or the name if no model is found.
|
|
1243
|
+
* @param projectDefinition - The project definition.
|
|
1244
|
+
* @param name - The name of the model.
|
|
1245
|
+
* @returns The ID of the model, or the name if no model is found.
|
|
1246
|
+
*/
|
|
1247
|
+
function getModelIdByNameOrDefault(projectDefinition, name) {
|
|
1248
|
+
return projectDefinition.models.find((m) => m.name === name)?.id ?? name;
|
|
1249
|
+
}
|
|
1250
|
+
const ModelUtils = {
|
|
1251
|
+
byId,
|
|
1252
|
+
byIdOrThrow,
|
|
1253
|
+
getScalarFieldById,
|
|
1254
|
+
getRelationsToModel,
|
|
1255
|
+
getModelsForFeature,
|
|
1256
|
+
getModelIdFields,
|
|
1257
|
+
hasService,
|
|
1258
|
+
validateModelName,
|
|
1259
|
+
getModelIdByNameOrDefault,
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
export { CASE_VALIDATORS as C, DefinitionEntityType as D, FeatureUtils as F, ModelUtils as M, ZodRefWrapper as Z, isEqual as a, createEntityType as b, createPluginSpec as c, get as d, eq as e, zRef as f, getSymbols as g, zEnt as h, isPlainObject as i, createDefinitionEntityNameResolver as j, ZodRef as k, featureEntityType as l, zRefBuilder as m, zRefId as n, featuresSchema as o, zPluginWrapper as p, ZodPluginWrapper as q, createInitializedPluginSpec as r, set as s, ZodRefBuilder as t, featureNameSchema as u, featureSchema as v, zodPluginSymbol as z };
|
|
1263
|
+
//# sourceMappingURL=model-utils-CbQJy1wE.js.map
|