@postxl/schema 0.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 (75) hide show
  1. package/LICENSE +50 -0
  2. package/README.md +320 -0
  3. package/dist/enum/enum.brands.d.ts +11 -0
  4. package/dist/enum/enum.brands.js +19 -0
  5. package/dist/enum/enum.d.ts +49 -0
  6. package/dist/enum/enum.defaults.d.ts +41 -0
  7. package/dist/enum/enum.defaults.js +105 -0
  8. package/dist/enum/enum.js +6 -0
  9. package/dist/enum/enum.json-decoder.d.ts +61 -0
  10. package/dist/enum/enum.json-decoder.js +51 -0
  11. package/dist/enum/enum.transformer.d.ts +12 -0
  12. package/dist/enum/enum.transformer.js +76 -0
  13. package/dist/enum/enum.types.d.ts +14 -0
  14. package/dist/enum/enum.types.js +2 -0
  15. package/dist/enum/index.d.ts +6 -0
  16. package/dist/enum/index.js +22 -0
  17. package/dist/field/defaults.d.ts +12 -0
  18. package/dist/field/defaults.js +78 -0
  19. package/dist/field/discriminated-union.d.ts +125 -0
  20. package/dist/field/discriminated-union.js +207 -0
  21. package/dist/field/enum.d.ts +65 -0
  22. package/dist/field/enum.js +111 -0
  23. package/dist/field/field.d.ts +483 -0
  24. package/dist/field/field.js +68 -0
  25. package/dist/field/id.d.ts +152 -0
  26. package/dist/field/id.js +104 -0
  27. package/dist/field/index.d.ts +11 -0
  28. package/dist/field/index.js +27 -0
  29. package/dist/field/relation.d.ts +88 -0
  30. package/dist/field/relation.js +138 -0
  31. package/dist/field/scalar.d.ts +179 -0
  32. package/dist/field/scalar.js +197 -0
  33. package/dist/field/shared/brands.d.ts +38 -0
  34. package/dist/field/shared/brands.js +109 -0
  35. package/dist/field/shared/decoders.d.ts +17 -0
  36. package/dist/field/shared/decoders.js +88 -0
  37. package/dist/field/shared/seed.d.ts +32 -0
  38. package/dist/field/shared/seed.js +63 -0
  39. package/dist/field/shared/types.d.ts +73 -0
  40. package/dist/field/shared/types.js +2 -0
  41. package/dist/field/shared/utils.d.ts +26 -0
  42. package/dist/field/shared/utils.js +52 -0
  43. package/dist/index.d.ts +12 -0
  44. package/dist/index.js +25 -0
  45. package/dist/model/index.d.ts +5 -0
  46. package/dist/model/index.js +21 -0
  47. package/dist/model/model.brands.d.ts +7 -0
  48. package/dist/model/model.brands.js +10 -0
  49. package/dist/model/model.defaults.d.ts +28 -0
  50. package/dist/model/model.defaults.js +304 -0
  51. package/dist/model/model.json-decoder.d.ts +94 -0
  52. package/dist/model/model.json-decoder.js +107 -0
  53. package/dist/model/model.transformer.d.ts +93 -0
  54. package/dist/model/model.transformer.js +183 -0
  55. package/dist/model/model.types.d.ts +37 -0
  56. package/dist/model/model.types.js +2 -0
  57. package/dist/project-schema/project-schema.brands.d.ts +10 -0
  58. package/dist/project-schema/project-schema.brands.js +17 -0
  59. package/dist/project-schema/project-schema.defaults.d.ts +16 -0
  60. package/dist/project-schema/project-schema.defaults.js +53 -0
  61. package/dist/project-schema/project-schema.json-decoder.d.ts +285 -0
  62. package/dist/project-schema/project-schema.json-decoder.js +145 -0
  63. package/dist/project-schema/project-schema.transformer.d.ts +284 -0
  64. package/dist/project-schema/project-schema.transformer.js +444 -0
  65. package/dist/project-schema/project-schema.types.d.ts +77 -0
  66. package/dist/project-schema/project-schema.types.js +2 -0
  67. package/dist/samples/la.schema.json +2055 -0
  68. package/dist/samples/mca.schema.json +830 -0
  69. package/dist/samples/ring.schema.json +879 -0
  70. package/dist/samples/sample-schemas.d.ts +1896 -0
  71. package/dist/samples/sample-schemas.js +20 -0
  72. package/dist/samples/simple.schema.json +250 -0
  73. package/dist/samples/subex.schema.json +1188 -0
  74. package/dist/samples/usp-msm.schema.json +2515 -0
  75. package/package.json +57 -0
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ import * as Decoders from './decoders';
3
+ declare const _seedDecoder: z.ZodObject<{
4
+ seed: z.ZodOptional<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodDate]>, "many">]>>;
5
+ faker: z.ZodOptional<z.ZodString>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ faker?: string | undefined;
8
+ seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
9
+ }, {
10
+ faker?: string | undefined;
11
+ seed?: string | number | boolean | Date | (string | number | boolean | Date)[] | undefined;
12
+ }>;
13
+ type Decoded = z.infer<typeof _seedDecoder>;
14
+ export type FieldSeedConfig = FieldSeedConfig_Default | FieldSeedConfig_Const | FieldSeedConfig_Array | FieldSeedConfig_Faker;
15
+ export type FieldSeedConfig_Default = {
16
+ type: 'default';
17
+ };
18
+ type ScalarValue = z.infer<typeof Decoders.zScalarValue>;
19
+ export type FieldSeedConfig_Const = {
20
+ type: 'const';
21
+ seed: ScalarValue;
22
+ };
23
+ export type FieldSeedConfig_Array = {
24
+ type: 'array';
25
+ seed: ScalarValue[];
26
+ };
27
+ export type FieldSeedConfig_Faker = {
28
+ type: 'faker';
29
+ faker: string;
30
+ };
31
+ export declare function seedTransformer(source: Decoded, ctx: z.RefinementCtx): FieldSeedConfig;
32
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.seedTransformer = seedTransformer;
37
+ const zod_1 = require("zod");
38
+ const Decoders = __importStar(require("./decoders"));
39
+ const _seedDecoder = zod_1.z.object({
40
+ seed: Decoders.zFieldSeed,
41
+ faker: Decoders.zFieldFaker,
42
+ });
43
+ function seedTransformer(source, ctx) {
44
+ if (source.seed === undefined && source.faker === undefined) {
45
+ return { type: 'default' };
46
+ }
47
+ if (source.seed !== undefined && source.faker !== undefined) {
48
+ ctx.addIssue({
49
+ code: zod_1.z.ZodIssueCode.custom,
50
+ message: 'Seed and faker cannot be used together - please provided only one of them!',
51
+ });
52
+ return { type: 'default' };
53
+ }
54
+ if (source.seed !== undefined) {
55
+ if (Array.isArray(source.seed)) {
56
+ return { type: 'array', seed: source.seed };
57
+ }
58
+ else {
59
+ return { type: 'const', seed: source.seed };
60
+ }
61
+ }
62
+ return { type: 'faker', faker: source.faker };
63
+ }
@@ -0,0 +1,73 @@
1
+ import { z } from 'zod';
2
+ import { Enums } from '../../enum';
3
+ import { ModelName } from '../../model';
4
+ import { FieldEnriched } from '../field';
5
+ import * as Branded from './brands';
6
+ /**
7
+ * Properties shared by all field types. The `kind` property is used to discriminate between different field types.
8
+ */
9
+ export type FieldCore<Kind extends string> = {
10
+ /**
11
+ * The kind of the field. This is used to discriminate between different field types.
12
+ */
13
+ kind: Kind;
14
+ /**
15
+ * Name of the field and variable (e.g. name). Should be camelCased.
16
+ */
17
+ name: Branded.FieldName;
18
+ /**
19
+ * A helpful description of the field. Will be used as JSDoc documentation in the generated type.
20
+ */
21
+ description: string | undefined;
22
+ };
23
+ /**
24
+ * Properties shared by most field types
25
+ */
26
+ export type FieldCommon<T extends string> = FieldCore<T> & {
27
+ /**
28
+ * Name of the model the field belongs to.
29
+ */
30
+ modelName: ModelName;
31
+ /**
32
+ * Mapping of the field to the database column. If not provided, we use the `name` field.
33
+ */
34
+ databaseName: Branded.DatabaseFieldName;
35
+ /**
36
+ * Mapping of the field to an Excel column name. If not provided, we use the `label` field.
37
+ */
38
+ excelName: Branded.ExcelColumnName;
39
+ /**
40
+ * The type of the field in the database.
41
+ */
42
+ databaseType: Branded.DatabaseFieldType;
43
+ /**
44
+ * The human readable label/name of the field. Used for instance in generated forms to label fields.\n\nIf not provided, we use the `name` field.
45
+ */
46
+ label: string;
47
+ /**
48
+ * If true, the field must be provided. If false, the field is optional.
49
+ */
50
+ isRequired: boolean;
51
+ /**
52
+ * If true, the field is readonly, ie. it cannot be changed by the user.
53
+ */
54
+ isReadonly: boolean;
55
+ /**
56
+ * If true, uniqueness is enforced for the field, ie no two items can have the same value for this field.
57
+ */
58
+ isUnique: boolean;
59
+ };
60
+ export type FieldTransformer<Kind extends string, Enriched, Full extends FieldCore<Kind>> = (params: {
61
+ fieldInput: Enriched;
62
+ model: {
63
+ name: ModelName;
64
+ fields: Map<Branded.FieldName, FieldEnriched>;
65
+ };
66
+ projectSchema: {
67
+ enums: Enums;
68
+ models: Map<ModelName, {
69
+ name: ModelName;
70
+ isReadonly?: boolean;
71
+ }>;
72
+ };
73
+ }, ctx: z.RefinementCtx) => Full;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ import { ModelName } from '../../model';
2
+ import { Field, FieldEnriched } from '../field';
3
+ import { FieldIdEnriched } from '../id';
4
+ import { FieldName } from './brands';
5
+ /**
6
+ * Checks if a field is required or optional.
7
+ *
8
+ * This is done by checking for the presence of a question mark at the end of the type.
9
+ * In this case, it is optional and we remove it.
10
+ */
11
+ export declare function isFieldRequired<T extends string>(
12
+ /**
13
+ * The original type of the field as provided in the JSON schema. If it ends with a question mark, it is optional.
14
+ */
15
+ type: T): {
16
+ isRequired: boolean;
17
+ type: T;
18
+ };
19
+ export declare function getIdField(model: {
20
+ name: ModelName;
21
+ fields: Map<FieldName, FieldEnriched>;
22
+ }): FieldIdEnriched | undefined;
23
+ /**
24
+ * Returns the type of the field as provided in the JSON schema.
25
+ */
26
+ export declare function getFieldType(field: Field): string;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFieldRequired = isFieldRequired;
4
+ exports.getIdField = getIdField;
5
+ exports.getFieldType = getFieldType;
6
+ const utils_1 = require("@postxl/utils");
7
+ /**
8
+ * Checks if a field is required or optional.
9
+ *
10
+ * This is done by checking for the presence of a question mark at the end of the type.
11
+ * In this case, it is optional and we remove it.
12
+ */
13
+ function isFieldRequired(
14
+ /**
15
+ * The original type of the field as provided in the JSON schema. If it ends with a question mark, it is optional.
16
+ */
17
+ type) {
18
+ if (type.endsWith('?')) {
19
+ return {
20
+ isRequired: false,
21
+ type: type.slice(0, -1),
22
+ };
23
+ }
24
+ return { isRequired: true, type };
25
+ }
26
+ function getIdField(model) {
27
+ for (const field of model.fields.values()) {
28
+ if (field.kind === 'id') {
29
+ return field;
30
+ }
31
+ }
32
+ return undefined;
33
+ }
34
+ /**
35
+ * Returns the type of the field as provided in the JSON schema.
36
+ */
37
+ function getFieldType(field) {
38
+ switch (field.kind) {
39
+ case 'id':
40
+ return field.databaseType;
41
+ case 'scalar':
42
+ return field.databaseType;
43
+ case 'discriminatedUnion':
44
+ return 'DiscriminatedUnion';
45
+ case 'relation':
46
+ return field.type;
47
+ case 'enum':
48
+ return field.type;
49
+ default:
50
+ throw new utils_1.ExhaustiveSwitchCheck(field);
51
+ }
52
+ }
@@ -0,0 +1,12 @@
1
+ export { zProjectSchema } from './project-schema/project-schema.transformer';
2
+ export * from './project-schema/project-schema.brands';
3
+ export * from './project-schema/project-schema.types';
4
+ export type { ProjectSchemaJSON } from './project-schema/project-schema.json-decoder';
5
+ export type * from './enum/enum.brands';
6
+ export * from './enum/enum.defaults';
7
+ export type * from './enum/enum.types';
8
+ export * from './field';
9
+ export type * from './model/model.brands';
10
+ export * from './model/model.defaults';
11
+ export type * from './model/model.types';
12
+ export * from './samples/sample-schemas';
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.zProjectSchema = void 0;
18
+ var project_schema_transformer_1 = require("./project-schema/project-schema.transformer");
19
+ Object.defineProperty(exports, "zProjectSchema", { enumerable: true, get: function () { return project_schema_transformer_1.zProjectSchema; } });
20
+ __exportStar(require("./project-schema/project-schema.brands"), exports);
21
+ __exportStar(require("./project-schema/project-schema.types"), exports);
22
+ __exportStar(require("./enum/enum.defaults"), exports);
23
+ __exportStar(require("./field"), exports);
24
+ __exportStar(require("./model/model.defaults"), exports);
25
+ __exportStar(require("./samples/sample-schemas"), exports);
@@ -0,0 +1,5 @@
1
+ export * from './model.brands';
2
+ export * from './model.defaults';
3
+ export * from './model.json-decoder';
4
+ export * from './model.transformer';
5
+ export * from './model.types';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./model.brands"), exports);
18
+ __exportStar(require("./model.defaults"), exports);
19
+ __exportStar(require("./model.json-decoder"), exports);
20
+ __exportStar(require("./model.transformer"), exports);
21
+ __exportStar(require("./model.types"), exports);
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ export declare const zModelName: z.ZodBranded<z.ZodString, "PXL.ModelName">;
3
+ export type ModelName = z.infer<typeof zModelName>;
4
+ export declare const toModelName: (input: string) => string & z.BRAND<"PXL.ModelName">;
5
+ export declare const zDatabaseModelName: z.ZodBranded<z.ZodString, "PXL.DatabaseModelName">;
6
+ export type DatabaseModelName = z.infer<typeof zDatabaseModelName>;
7
+ export declare const toDatabaseModelName: (input: string) => string & z.BRAND<"PXL.DatabaseModelName">;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDatabaseModelName = exports.zDatabaseModelName = exports.toModelName = exports.zModelName = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.zModelName = zod_1.z.string().brand('PXL.ModelName');
6
+ const toModelName = (input) => exports.zModelName.parse(input);
7
+ exports.toModelName = toModelName;
8
+ exports.zDatabaseModelName = zod_1.z.string().brand('PXL.DatabaseModelName');
9
+ const toDatabaseModelName = (input) => exports.zDatabaseModelName.parse(input);
10
+ exports.toDatabaseModelName = toDatabaseModelName;
@@ -0,0 +1,28 @@
1
+ import * as Branded from './model.brands';
2
+ import { ModelJSON } from './model.json-decoder';
3
+ export declare const defaultModelName_Config: string & import("zod").BRAND<"PXL.ModelName">;
4
+ export declare const standardModelName_User: string & import("zod").BRAND<"PXL.ModelName">;
5
+ export declare const standardModelName_Action: string & import("zod").BRAND<"PXL.ModelName">;
6
+ export declare const standardModelName_ActionOperation: string & import("zod").BRAND<"PXL.ModelName">;
7
+ export declare const standardModelName_File: string & import("zod").BRAND<"PXL.ModelName">;
8
+ export declare const defaultModelNames: {
9
+ config: string & import("zod").BRAND<"PXL.ModelName">;
10
+ user: string & import("zod").BRAND<"PXL.ModelName">;
11
+ action: string & import("zod").BRAND<"PXL.ModelName">;
12
+ mutation: string & import("zod").BRAND<"PXL.ModelName">;
13
+ file: string & import("zod").BRAND<"PXL.ModelName">;
14
+ };
15
+ export declare const defaultModel_Config: ModelJSON;
16
+ export declare const defaultModelJson_User: ModelJSON;
17
+ export declare const defaultModelJson_Action: ModelJSON & {
18
+ repository: {
19
+ type: string;
20
+ };
21
+ };
22
+ export declare const defaultModelJson_ActionOperation: ModelJSON & {
23
+ repository: {
24
+ type: string;
25
+ };
26
+ };
27
+ export declare const defaultModelJson_File: ModelJSON;
28
+ export declare const defaultModelsJson: Record<Branded.ModelName, ModelJSON>;
@@ -0,0 +1,304 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.defaultModelsJson = exports.defaultModelJson_File = exports.defaultModelJson_ActionOperation = exports.defaultModelJson_Action = exports.defaultModelJson_User = exports.defaultModel_Config = exports.defaultModelNames = exports.standardModelName_File = exports.standardModelName_ActionOperation = exports.standardModelName_Action = exports.standardModelName_User = exports.defaultModelName_Config = void 0;
37
+ const defaults_1 = require("../field/defaults");
38
+ const project_schema_defaults_1 = require("../project-schema/project-schema.defaults");
39
+ const Branded = __importStar(require("./model.brands"));
40
+ exports.defaultModelName_Config = Branded.toModelName('Config');
41
+ exports.standardModelName_User = Branded.toModelName('User');
42
+ exports.standardModelName_Action = Branded.toModelName('Action');
43
+ exports.standardModelName_ActionOperation = Branded.toModelName('ActionOperation');
44
+ exports.standardModelName_File = Branded.toModelName('File');
45
+ exports.defaultModelNames = {
46
+ config: exports.defaultModelName_Config,
47
+ user: exports.standardModelName_User,
48
+ action: exports.standardModelName_Action,
49
+ mutation: exports.standardModelName_ActionOperation,
50
+ file: exports.standardModelName_File,
51
+ };
52
+ exports.defaultModel_Config = {
53
+ name: exports.defaultModelName_Config,
54
+ description: 'The configuration of the project.',
55
+ schema: project_schema_defaults_1.databaseSchemaNameConfig,
56
+ standardFields: [defaults_1.standardFieldName_id],
57
+ fields: [
58
+ {
59
+ name: 'version',
60
+ type: 'String',
61
+ description: 'The version of the project.',
62
+ label: 'Version',
63
+ isReadonly: true,
64
+ },
65
+ {
66
+ name: 'slug',
67
+ type: 'String',
68
+ description: 'The slug of the project.',
69
+ isReadonly: true,
70
+ label: 'Slug',
71
+ },
72
+ ],
73
+ seed: [{ id: 'Config', version: '0.0.1', slug: 'postxl-demo' }],
74
+ };
75
+ exports.defaultModelJson_User = {
76
+ name: exports.standardModelName_User,
77
+ description: 'A user of the application.',
78
+ schema: project_schema_defaults_1.databaseSchemaNameConfig,
79
+ fields: [
80
+ {
81
+ name: 'sub',
82
+ type: 'String?',
83
+ isUnique: true,
84
+ hasIndex: true,
85
+ description: 'The OpenID Connect provided subject identifier.',
86
+ faker: 'string.uuid()',
87
+ },
88
+ {
89
+ name: 'name',
90
+ type: 'String',
91
+ label: 'Name',
92
+ description: 'The name of the user.',
93
+ faker: 'person.fullName',
94
+ },
95
+ {
96
+ name: 'email',
97
+ type: 'String',
98
+ // validations: [
99
+ // {
100
+ // type: 'email',
101
+ // message: 'The email is not valid.',
102
+ // },
103
+ // ],
104
+ description: 'The email of the user.',
105
+ faker: 'internet.email',
106
+ },
107
+ {
108
+ name: 'profilePictureUrl',
109
+ type: 'String?',
110
+ description: 'The URL of the profile picture of the user.',
111
+ faker: 'image.avatar',
112
+ },
113
+ ],
114
+ faker: {
115
+ items: 3,
116
+ },
117
+ };
118
+ exports.defaultModelJson_Action = {
119
+ name: exports.standardModelName_Action,
120
+ description: 'An Action represents an attempt to change to the business state. This can be a simple CUD operation, e.g. creating a new entry for a model - or a complex business operation, e.g. approving a publication.',
121
+ isReadonly: true,
122
+ schema: project_schema_defaults_1.databaseSchemaNameConfig,
123
+ standardFields: [defaults_1.standardFieldName_id, defaults_1.standardFieldName_createdAt, defaults_1.standardFieldName_updatedAt],
124
+ labelField: defaults_1.standardFieldName_id,
125
+ fields: [
126
+ {
127
+ name: 'migrationOrder',
128
+ type: 'Int?',
129
+ description: 'If it is a migration action, the migrationOrder is the order of the migration within the migration sequence.',
130
+ },
131
+ {
132
+ name: 'userId',
133
+ type: 'User?',
134
+ description: 'The user that initiated the action.',
135
+ },
136
+ {
137
+ name: 'scope',
138
+ type: 'String',
139
+ description: 'The scope represents the discriminator for the business logic scope of the action. This typically corresponds to a model, but if business logic has more complex it can also map to other businessLogic services.',
140
+ },
141
+ {
142
+ name: 'type',
143
+ type: 'String?',
144
+ description: 'The type represents the discriminator for the action type of logic. It is used within the scoped business logic service to discriminate which action to execute.',
145
+ },
146
+ {
147
+ name: 'payload',
148
+ type: 'String?',
149
+ description: 'The payload is a JSON string that contains the data required to execute the action.',
150
+ },
151
+ {
152
+ name: 'status',
153
+ type: 'ActionStatus',
154
+ description: 'The status of the action.',
155
+ },
156
+ {
157
+ name: 'error',
158
+ type: 'String?',
159
+ description: 'In case of an error, the error field contains JSON string with the error details.',
160
+ },
161
+ {
162
+ name: 'result',
163
+ type: 'String?',
164
+ description: 'In case of a successful action, the result field contains the JSON string with the result details.',
165
+ },
166
+ ],
167
+ repository: { type: 'DatabaseDirect' },
168
+ faker: { items: 0 },
169
+ };
170
+ exports.defaultModelJson_ActionOperation = {
171
+ name: exports.standardModelName_ActionOperation,
172
+ description: `An \`ActionOperation\` represents a step in an action. It can either be a \`Transformation\` or a \`Mutation\`.
173
+ A \`Transformation\` changes the payload with some operation into a new shape. This could be extracting data from an Excel file, running a Zod decoder or other operations.
174
+ A \`Mutation\` represents a direct change (CUD) to a data entry of a model.`,
175
+ isReadonly: true,
176
+ schema: project_schema_defaults_1.databaseSchemaNameConfig,
177
+ standardFields: [defaults_1.standardFieldName_id, defaults_1.standardFieldName_createdAt, defaults_1.standardFieldName_updatedAt],
178
+ labelField: defaults_1.standardFieldName_id,
179
+ fields: [
180
+ {
181
+ name: 'actionId',
182
+ type: 'Action?',
183
+ description: 'The action that initiated the operation.',
184
+ },
185
+ {
186
+ name: 'order',
187
+ type: 'Int',
188
+ description: 'The order of the operation within the action.',
189
+ },
190
+ {
191
+ name: 'payload',
192
+ type: 'String?',
193
+ description: 'The payload is a JSON string that contains the data required to execute the mutation.',
194
+ },
195
+ {
196
+ name: 'status',
197
+ type: 'MutationStatus',
198
+ description: "The status of the mutation: 'Started' | 'Success' | 'Error'",
199
+ },
200
+ {
201
+ name: 'result',
202
+ type: 'String?',
203
+ description: `The result of the operation. Depending on mutation kind, it contains:
204
+ Create: new entity
205
+ CreateMany: Array of newly created entities
206
+ Update: Updated entity
207
+ UpdateMany: Array of updated entities
208
+ Delete, DeleteMany: Null
209
+ Clone: The cloned entity
210
+ Transformation: Depends on the transformation`,
211
+ },
212
+ {
213
+ name: 'error',
214
+ type: 'String?',
215
+ description: 'In case of an error: JSON string with the error details.',
216
+ },
217
+ {
218
+ name: 'content',
219
+ type: 'DiscriminatedUnion',
220
+ members: [
221
+ {
222
+ type: 'Transformation',
223
+ fields: [
224
+ {
225
+ name: 'operation',
226
+ type: 'String',
227
+ description: 'The operation that is executed on the payload.',
228
+ },
229
+ ],
230
+ },
231
+ {
232
+ type: 'Mutation',
233
+ fields: [
234
+ {
235
+ name: 'model',
236
+ type: 'String',
237
+ description: 'Which model is affected by the mutation.',
238
+ },
239
+ {
240
+ name: 'kind',
241
+ type: 'MutationKind',
242
+ description: "The type of the mutation: 'Create' | 'CreateMany' | 'Update' | 'Upsert' | 'Delete' | ...",
243
+ },
244
+ {
245
+ name: 'entityId',
246
+ type: 'String?',
247
+ description: "The id of the affected entity. Depending on the type of the mutation, this is the following:\n\t'Create': the newly created entity's ID\n\t'CreateMany': A stringified array of all created entities' IDs\n\t'Update' & 'Delete': id that was provided as input.",
248
+ },
249
+ {
250
+ name: 'sourceEntity',
251
+ type: 'String?',
252
+ description: 'The original entity before the mutation was executed. Null in case of a create mutation.',
253
+ },
254
+ ],
255
+ },
256
+ ],
257
+ },
258
+ ],
259
+ repository: { type: 'DatabaseDirect' },
260
+ faker: { items: 0 },
261
+ };
262
+ exports.defaultModelJson_File = {
263
+ name: exports.standardModelName_File,
264
+ description: 'A File represents a file that was uploaded by a user.',
265
+ schema: project_schema_defaults_1.databaseSchemaNameConfig,
266
+ fields: [
267
+ {
268
+ name: 'name',
269
+ type: 'String',
270
+ label: 'Name',
271
+ description: 'The name of the file.',
272
+ faker: 'system.commonFileName(png)',
273
+ },
274
+ {
275
+ name: 'mimetype',
276
+ type: 'String',
277
+ label: 'Mimetype',
278
+ description: 'The mimetype of the file.',
279
+ seed: ['image/png', 'image/jpeg', 'application/pdf'],
280
+ },
281
+ {
282
+ name: 'size',
283
+ type: 'Int?',
284
+ label: 'Size',
285
+ description: 'The size of the file in bytes.',
286
+ faker: 'number.int(2500000)',
287
+ },
288
+ {
289
+ name: 'url',
290
+ type: 'String',
291
+ label: 'Url',
292
+ description: 'The URL of the file.',
293
+ faker: 'image.avatar',
294
+ },
295
+ ],
296
+ faker: { items: 0 },
297
+ };
298
+ exports.defaultModelsJson = {
299
+ [exports.defaultModelName_Config]: exports.defaultModel_Config,
300
+ [exports.standardModelName_User]: exports.defaultModelJson_User,
301
+ [exports.standardModelName_Action]: exports.defaultModelJson_Action,
302
+ [exports.standardModelName_ActionOperation]: exports.defaultModelJson_ActionOperation,
303
+ [exports.standardModelName_File]: exports.defaultModelJson_File,
304
+ };