av6-core 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +116 -1
- package/dist/index.d.ts +116 -1
- package/dist/index.js +9 -9
- package/dist/index.mjs +9 -9
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -29,7 +29,122 @@ declare enum ErrorMessageType {
|
|
|
29
29
|
EXCEL = "No data found to be downloaded"
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
type Presence = "required" | "optional" | "forbidden";
|
|
33
|
+
type Op = "create" | "update";
|
|
34
|
+
type FieldType = "string" | "number" | "boolean" | "date" | "enum" | "object" | "array" | "json";
|
|
35
|
+
type SourcePath = `body.${string}` | `vars.${string}` | `ctx.${string}`;
|
|
36
|
+
interface FieldRules {
|
|
37
|
+
min?: number;
|
|
38
|
+
max?: number;
|
|
39
|
+
integer?: boolean;
|
|
40
|
+
trim?: boolean;
|
|
41
|
+
regex?: string;
|
|
42
|
+
values?: string[];
|
|
43
|
+
iso?: boolean;
|
|
44
|
+
schema?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
interface FieldConfig {
|
|
47
|
+
name: string;
|
|
48
|
+
db: string;
|
|
49
|
+
type: FieldType;
|
|
50
|
+
src?: SourcePath;
|
|
51
|
+
presence: Record<Op, Presence>;
|
|
52
|
+
rules?: FieldRules;
|
|
53
|
+
default?: unknown;
|
|
54
|
+
allowNull?: boolean;
|
|
55
|
+
messages?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
type RelationStrategy = "create" | "replace" | "upsert";
|
|
58
|
+
interface RelationWriteConfig {
|
|
59
|
+
strategy: RelationStrategy;
|
|
60
|
+
itemPrimaryKey?: string;
|
|
61
|
+
}
|
|
62
|
+
interface RelationConfig {
|
|
63
|
+
name: string;
|
|
64
|
+
db: string;
|
|
65
|
+
kind: "many" | "one";
|
|
66
|
+
presence: Record<Op, Presence>;
|
|
67
|
+
write: {
|
|
68
|
+
create: RelationWriteConfig;
|
|
69
|
+
update: RelationWriteConfig;
|
|
70
|
+
};
|
|
71
|
+
items: {
|
|
72
|
+
fields: FieldConfig[];
|
|
73
|
+
audit?: {
|
|
74
|
+
createdBy?: SourcePath;
|
|
75
|
+
updatedBy?: SourcePath;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
interface UniqueConfig {
|
|
80
|
+
name: string;
|
|
81
|
+
op: Op[];
|
|
82
|
+
where: Array<{
|
|
83
|
+
field: string;
|
|
84
|
+
src: SourcePath;
|
|
85
|
+
}>;
|
|
86
|
+
message: string;
|
|
87
|
+
}
|
|
88
|
+
interface DynamicCrudConfig {
|
|
89
|
+
version: number;
|
|
90
|
+
primaryKey: string;
|
|
91
|
+
validation: {
|
|
92
|
+
abortEarly: boolean;
|
|
93
|
+
allowUnknown: boolean;
|
|
94
|
+
stripUnknown: boolean;
|
|
95
|
+
convert: boolean;
|
|
96
|
+
};
|
|
97
|
+
audit?: {
|
|
98
|
+
createdByField?: string;
|
|
99
|
+
updatedByField?: string;
|
|
100
|
+
};
|
|
101
|
+
operations: {
|
|
102
|
+
create: {
|
|
103
|
+
requirePrimaryKey: boolean;
|
|
104
|
+
};
|
|
105
|
+
update: {
|
|
106
|
+
requirePrimaryKey: boolean;
|
|
107
|
+
primaryKeyFrom: "params" | "body" | "query";
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
uniques?: UniqueConfig[];
|
|
111
|
+
fields: FieldConfig[];
|
|
112
|
+
relations?: RelationConfig[];
|
|
113
|
+
response?: {
|
|
114
|
+
include?: Record<string, unknown>;
|
|
115
|
+
select?: Record<string, unknown> | null;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
interface CrudContext {
|
|
119
|
+
userId?: number;
|
|
120
|
+
vars?: Record<string, unknown>;
|
|
121
|
+
}
|
|
32
122
|
type TxClient = PrismaClient | Prisma.TransactionClient;
|
|
123
|
+
type CrudDelegate = {
|
|
124
|
+
create: (args: {
|
|
125
|
+
data: unknown;
|
|
126
|
+
include?: unknown;
|
|
127
|
+
select?: unknown;
|
|
128
|
+
}) => Promise<unknown>;
|
|
129
|
+
update: (args: {
|
|
130
|
+
where: Record<string, unknown>;
|
|
131
|
+
data: unknown;
|
|
132
|
+
include?: unknown;
|
|
133
|
+
select?: unknown;
|
|
134
|
+
}) => Promise<unknown>;
|
|
135
|
+
findFirst: (args: {
|
|
136
|
+
where: Record<string, unknown>;
|
|
137
|
+
select?: Record<string, boolean>;
|
|
138
|
+
}) => Promise<unknown>;
|
|
139
|
+
};
|
|
140
|
+
interface DynamicCreateInput {
|
|
141
|
+
shortCodeData: DynamicShortCode;
|
|
142
|
+
body: Record<string, unknown>;
|
|
143
|
+
ctx: CrudContext;
|
|
144
|
+
}
|
|
145
|
+
interface DynamicUpdateInput extends DynamicCreateInput {
|
|
146
|
+
id: number;
|
|
147
|
+
}
|
|
33
148
|
|
|
34
149
|
interface EmployeeCache {
|
|
35
150
|
id: number;
|
|
@@ -474,4 +589,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
474
589
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
475
590
|
}
|
|
476
591
|
|
|
477
|
-
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
592
|
+
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UniqueConfig, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,122 @@ declare enum ErrorMessageType {
|
|
|
29
29
|
EXCEL = "No data found to be downloaded"
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
type Presence = "required" | "optional" | "forbidden";
|
|
33
|
+
type Op = "create" | "update";
|
|
34
|
+
type FieldType = "string" | "number" | "boolean" | "date" | "enum" | "object" | "array" | "json";
|
|
35
|
+
type SourcePath = `body.${string}` | `vars.${string}` | `ctx.${string}`;
|
|
36
|
+
interface FieldRules {
|
|
37
|
+
min?: number;
|
|
38
|
+
max?: number;
|
|
39
|
+
integer?: boolean;
|
|
40
|
+
trim?: boolean;
|
|
41
|
+
regex?: string;
|
|
42
|
+
values?: string[];
|
|
43
|
+
iso?: boolean;
|
|
44
|
+
schema?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
interface FieldConfig {
|
|
47
|
+
name: string;
|
|
48
|
+
db: string;
|
|
49
|
+
type: FieldType;
|
|
50
|
+
src?: SourcePath;
|
|
51
|
+
presence: Record<Op, Presence>;
|
|
52
|
+
rules?: FieldRules;
|
|
53
|
+
default?: unknown;
|
|
54
|
+
allowNull?: boolean;
|
|
55
|
+
messages?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
type RelationStrategy = "create" | "replace" | "upsert";
|
|
58
|
+
interface RelationWriteConfig {
|
|
59
|
+
strategy: RelationStrategy;
|
|
60
|
+
itemPrimaryKey?: string;
|
|
61
|
+
}
|
|
62
|
+
interface RelationConfig {
|
|
63
|
+
name: string;
|
|
64
|
+
db: string;
|
|
65
|
+
kind: "many" | "one";
|
|
66
|
+
presence: Record<Op, Presence>;
|
|
67
|
+
write: {
|
|
68
|
+
create: RelationWriteConfig;
|
|
69
|
+
update: RelationWriteConfig;
|
|
70
|
+
};
|
|
71
|
+
items: {
|
|
72
|
+
fields: FieldConfig[];
|
|
73
|
+
audit?: {
|
|
74
|
+
createdBy?: SourcePath;
|
|
75
|
+
updatedBy?: SourcePath;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
interface UniqueConfig {
|
|
80
|
+
name: string;
|
|
81
|
+
op: Op[];
|
|
82
|
+
where: Array<{
|
|
83
|
+
field: string;
|
|
84
|
+
src: SourcePath;
|
|
85
|
+
}>;
|
|
86
|
+
message: string;
|
|
87
|
+
}
|
|
88
|
+
interface DynamicCrudConfig {
|
|
89
|
+
version: number;
|
|
90
|
+
primaryKey: string;
|
|
91
|
+
validation: {
|
|
92
|
+
abortEarly: boolean;
|
|
93
|
+
allowUnknown: boolean;
|
|
94
|
+
stripUnknown: boolean;
|
|
95
|
+
convert: boolean;
|
|
96
|
+
};
|
|
97
|
+
audit?: {
|
|
98
|
+
createdByField?: string;
|
|
99
|
+
updatedByField?: string;
|
|
100
|
+
};
|
|
101
|
+
operations: {
|
|
102
|
+
create: {
|
|
103
|
+
requirePrimaryKey: boolean;
|
|
104
|
+
};
|
|
105
|
+
update: {
|
|
106
|
+
requirePrimaryKey: boolean;
|
|
107
|
+
primaryKeyFrom: "params" | "body" | "query";
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
uniques?: UniqueConfig[];
|
|
111
|
+
fields: FieldConfig[];
|
|
112
|
+
relations?: RelationConfig[];
|
|
113
|
+
response?: {
|
|
114
|
+
include?: Record<string, unknown>;
|
|
115
|
+
select?: Record<string, unknown> | null;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
interface CrudContext {
|
|
119
|
+
userId?: number;
|
|
120
|
+
vars?: Record<string, unknown>;
|
|
121
|
+
}
|
|
32
122
|
type TxClient = PrismaClient | Prisma.TransactionClient;
|
|
123
|
+
type CrudDelegate = {
|
|
124
|
+
create: (args: {
|
|
125
|
+
data: unknown;
|
|
126
|
+
include?: unknown;
|
|
127
|
+
select?: unknown;
|
|
128
|
+
}) => Promise<unknown>;
|
|
129
|
+
update: (args: {
|
|
130
|
+
where: Record<string, unknown>;
|
|
131
|
+
data: unknown;
|
|
132
|
+
include?: unknown;
|
|
133
|
+
select?: unknown;
|
|
134
|
+
}) => Promise<unknown>;
|
|
135
|
+
findFirst: (args: {
|
|
136
|
+
where: Record<string, unknown>;
|
|
137
|
+
select?: Record<string, boolean>;
|
|
138
|
+
}) => Promise<unknown>;
|
|
139
|
+
};
|
|
140
|
+
interface DynamicCreateInput {
|
|
141
|
+
shortCodeData: DynamicShortCode;
|
|
142
|
+
body: Record<string, unknown>;
|
|
143
|
+
ctx: CrudContext;
|
|
144
|
+
}
|
|
145
|
+
interface DynamicUpdateInput extends DynamicCreateInput {
|
|
146
|
+
id: number;
|
|
147
|
+
}
|
|
33
148
|
|
|
34
149
|
interface EmployeeCache {
|
|
35
150
|
id: number;
|
|
@@ -474,4 +589,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
474
589
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
475
590
|
}
|
|
476
591
|
|
|
477
|
-
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
592
|
+
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UniqueConfig, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.js
CHANGED
|
@@ -807,7 +807,7 @@ var omitUndefined = (obj) => {
|
|
|
807
807
|
|
|
808
808
|
// src/utils/dynamicPrismaBuilder.utils.ts
|
|
809
809
|
var resolveSrc = (f, env) => {
|
|
810
|
-
const src = f.src ?? `body.${f.
|
|
810
|
+
const src = f.src ?? `body.${f.db}`;
|
|
811
811
|
if (src.startsWith("body.")) return getByPath(env.body, src.slice(5));
|
|
812
812
|
if (src.startsWith("vars.")) return getByPath(env.ctx.vars ?? {}, src.slice(5));
|
|
813
813
|
if (src.startsWith("ctx.")) return getByPath(env.ctx, src.slice(4));
|
|
@@ -822,7 +822,7 @@ var setAudit = (cfg, op, out, ctx) => {
|
|
|
822
822
|
var buildScalarData = (cfg, op, env) => {
|
|
823
823
|
const out = {};
|
|
824
824
|
for (const f of cfg.fields) {
|
|
825
|
-
const dbKey = f.db
|
|
825
|
+
const dbKey = f.db;
|
|
826
826
|
const presence = f.presence[op];
|
|
827
827
|
if (presence === "forbidden") continue;
|
|
828
828
|
if (dbKey === cfg.primaryKey) continue;
|
|
@@ -835,7 +835,7 @@ var buildScalarData = (cfg, op, env) => {
|
|
|
835
835
|
return out;
|
|
836
836
|
};
|
|
837
837
|
var buildRelationWrite = (rel, op, env) => {
|
|
838
|
-
const raw = env.body[rel.
|
|
838
|
+
const raw = env.body[rel.db];
|
|
839
839
|
if (raw === void 0) return void 0;
|
|
840
840
|
const writeCfg = op === "create" ? rel.write.create : rel.write.update;
|
|
841
841
|
const itemPrimaryKey = writeCfg.itemPrimaryKey ?? "id";
|
|
@@ -843,11 +843,11 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
843
843
|
const itemBody = isRecord(item) ? item : {};
|
|
844
844
|
const itemOut = {};
|
|
845
845
|
for (const f of rel.items.fields) {
|
|
846
|
-
const dbKey = f.db
|
|
846
|
+
const dbKey = f.db;
|
|
847
847
|
const presence = f.presence[itemOp];
|
|
848
848
|
if (presence === "forbidden") continue;
|
|
849
849
|
if (dbKey === itemPrimaryKey) continue;
|
|
850
|
-
const v = itemBody[f.
|
|
850
|
+
const v = itemBody[f.db];
|
|
851
851
|
if (v === void 0) continue;
|
|
852
852
|
if (v === null && !f.allowNull) continue;
|
|
853
853
|
itemOut[dbKey] = v;
|
|
@@ -927,7 +927,7 @@ var buildPrismaData = (cfg, op, validatedBody, ctx) => {
|
|
|
927
927
|
const out = buildScalarData(cfg, op, env);
|
|
928
928
|
for (const rel of cfg.relations ?? []) {
|
|
929
929
|
const write = buildRelationWrite(rel, op, env);
|
|
930
|
-
if (write) out[rel.
|
|
930
|
+
if (write) out[rel.db] = write;
|
|
931
931
|
}
|
|
932
932
|
return out;
|
|
933
933
|
};
|
|
@@ -1138,7 +1138,7 @@ var buildRelationSchema = (rel, op) => {
|
|
|
1138
1138
|
const itemShape = {};
|
|
1139
1139
|
for (const f of rel.items.fields) {
|
|
1140
1140
|
const scalar = buildScalar(f);
|
|
1141
|
-
itemShape[f.
|
|
1141
|
+
itemShape[f.db] = applyPresence(scalar, f.presence[op]);
|
|
1142
1142
|
}
|
|
1143
1143
|
const itemSchema = import_joi.default.object(itemShape);
|
|
1144
1144
|
const base = rel.kind === "many" ? import_joi.default.array().items(itemSchema) : itemSchema;
|
|
@@ -1148,10 +1148,10 @@ var buildJoiSchemaForOp = (cfg, op) => {
|
|
|
1148
1148
|
const shape = {};
|
|
1149
1149
|
for (const f of cfg.fields) {
|
|
1150
1150
|
const scalar = buildScalar(f);
|
|
1151
|
-
shape[f.
|
|
1151
|
+
shape[f.db] = applyPresence(scalar, f.presence[op]);
|
|
1152
1152
|
}
|
|
1153
1153
|
for (const rel of cfg.relations ?? []) {
|
|
1154
|
-
shape[rel.
|
|
1154
|
+
shape[rel.db] = buildRelationSchema(rel, op);
|
|
1155
1155
|
}
|
|
1156
1156
|
return import_joi.default.object(shape).prefs({
|
|
1157
1157
|
abortEarly: cfg.validation.abortEarly,
|
package/dist/index.mjs
CHANGED
|
@@ -757,7 +757,7 @@ var omitUndefined = (obj) => {
|
|
|
757
757
|
|
|
758
758
|
// src/utils/dynamicPrismaBuilder.utils.ts
|
|
759
759
|
var resolveSrc = (f, env) => {
|
|
760
|
-
const src = f.src ?? `body.${f.
|
|
760
|
+
const src = f.src ?? `body.${f.db}`;
|
|
761
761
|
if (src.startsWith("body.")) return getByPath(env.body, src.slice(5));
|
|
762
762
|
if (src.startsWith("vars.")) return getByPath(env.ctx.vars ?? {}, src.slice(5));
|
|
763
763
|
if (src.startsWith("ctx.")) return getByPath(env.ctx, src.slice(4));
|
|
@@ -772,7 +772,7 @@ var setAudit = (cfg, op, out, ctx) => {
|
|
|
772
772
|
var buildScalarData = (cfg, op, env) => {
|
|
773
773
|
const out = {};
|
|
774
774
|
for (const f of cfg.fields) {
|
|
775
|
-
const dbKey = f.db
|
|
775
|
+
const dbKey = f.db;
|
|
776
776
|
const presence = f.presence[op];
|
|
777
777
|
if (presence === "forbidden") continue;
|
|
778
778
|
if (dbKey === cfg.primaryKey) continue;
|
|
@@ -785,7 +785,7 @@ var buildScalarData = (cfg, op, env) => {
|
|
|
785
785
|
return out;
|
|
786
786
|
};
|
|
787
787
|
var buildRelationWrite = (rel, op, env) => {
|
|
788
|
-
const raw = env.body[rel.
|
|
788
|
+
const raw = env.body[rel.db];
|
|
789
789
|
if (raw === void 0) return void 0;
|
|
790
790
|
const writeCfg = op === "create" ? rel.write.create : rel.write.update;
|
|
791
791
|
const itemPrimaryKey = writeCfg.itemPrimaryKey ?? "id";
|
|
@@ -793,11 +793,11 @@ var buildRelationWrite = (rel, op, env) => {
|
|
|
793
793
|
const itemBody = isRecord(item) ? item : {};
|
|
794
794
|
const itemOut = {};
|
|
795
795
|
for (const f of rel.items.fields) {
|
|
796
|
-
const dbKey = f.db
|
|
796
|
+
const dbKey = f.db;
|
|
797
797
|
const presence = f.presence[itemOp];
|
|
798
798
|
if (presence === "forbidden") continue;
|
|
799
799
|
if (dbKey === itemPrimaryKey) continue;
|
|
800
|
-
const v = itemBody[f.
|
|
800
|
+
const v = itemBody[f.db];
|
|
801
801
|
if (v === void 0) continue;
|
|
802
802
|
if (v === null && !f.allowNull) continue;
|
|
803
803
|
itemOut[dbKey] = v;
|
|
@@ -877,7 +877,7 @@ var buildPrismaData = (cfg, op, validatedBody, ctx) => {
|
|
|
877
877
|
const out = buildScalarData(cfg, op, env);
|
|
878
878
|
for (const rel of cfg.relations ?? []) {
|
|
879
879
|
const write = buildRelationWrite(rel, op, env);
|
|
880
|
-
if (write) out[rel.
|
|
880
|
+
if (write) out[rel.db] = write;
|
|
881
881
|
}
|
|
882
882
|
return out;
|
|
883
883
|
};
|
|
@@ -1088,7 +1088,7 @@ var buildRelationSchema = (rel, op) => {
|
|
|
1088
1088
|
const itemShape = {};
|
|
1089
1089
|
for (const f of rel.items.fields) {
|
|
1090
1090
|
const scalar = buildScalar(f);
|
|
1091
|
-
itemShape[f.
|
|
1091
|
+
itemShape[f.db] = applyPresence(scalar, f.presence[op]);
|
|
1092
1092
|
}
|
|
1093
1093
|
const itemSchema = Joi.object(itemShape);
|
|
1094
1094
|
const base = rel.kind === "many" ? Joi.array().items(itemSchema) : itemSchema;
|
|
@@ -1098,10 +1098,10 @@ var buildJoiSchemaForOp = (cfg, op) => {
|
|
|
1098
1098
|
const shape = {};
|
|
1099
1099
|
for (const f of cfg.fields) {
|
|
1100
1100
|
const scalar = buildScalar(f);
|
|
1101
|
-
shape[f.
|
|
1101
|
+
shape[f.db] = applyPresence(scalar, f.presence[op]);
|
|
1102
1102
|
}
|
|
1103
1103
|
for (const rel of cfg.relations ?? []) {
|
|
1104
|
-
shape[rel.
|
|
1104
|
+
shape[rel.db] = buildRelationSchema(rel, op);
|
|
1105
1105
|
}
|
|
1106
1106
|
return Joi.object(shape).prefs({
|
|
1107
1107
|
abortEarly: cfg.validation.abortEarly,
|