mandarina-server 1.6.5 → 2.0.0
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/build/Action/CustomAction.d.ts +4 -2
- package/build/Action/CustomAction.js +14 -2
- package/build/Action/CustomAction.js.map +1 -1
- package/build/Table/Table.d.ts +19 -18
- package/build/Table/Table.js +31 -28
- package/build/Table/Table.js.map +1 -1
- package/build/cli/gen-files/prisma2.d.ts +1 -0
- package/build/cli/gen-files/prisma2.js +284 -0
- package/build/cli/gen-files/prisma2.js.map +1 -0
- package/build/cli/index.js +5 -0
- package/build/cli/index.js.map +1 -1
- package/build/cli/utils.d.ts +4 -0
- package/build/cli/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/Action/CustomAction.ts +13 -5
- package/src/Table/Table.ts +42 -25
- package/src/cli/gen-files/prisma2.ts +277 -0
- package/src/cli/index.ts +6 -0
- package/src/cli/utils.js +5 -2
- package/src/cli/utils.js.map +1 -1
- package/src/cli/utils.ts +7 -3
- package/tmp/client/components/Common/Cells/CellDateTime.js +22 -0
- package/tmp/client/components/Common/Cells/CellDateTime.js.map +1 -0
- package/tmp/client/components/Common/Cells/CellHtml.js +13 -0
- package/tmp/client/components/Common/Cells/CellHtml.js.map +1 -0
- package/tmp/client/components/Common/Cells/CellLinkTemplate.js +19 -0
- package/tmp/client/components/Common/Cells/CellLinkTemplate.js.map +1 -0
- package/tmp/client/components/Common/ConfigurationContext.js +25 -0
- package/tmp/client/components/Common/ConfigurationContext.js.map +1 -0
- package/tmp/client/components/Common/My/MySchema.js +27 -0
- package/tmp/client/components/Common/My/MySchema.js.map +1 -0
- package/tmp/client/components/Common/uniforms/AddressField/AddressField.js +139 -0
- package/tmp/client/components/Common/uniforms/AddressField/AddressField.js.map +1 -0
- package/tmp/client/components/Common/uniforms/AddressField/utils.js +99 -0
- package/tmp/client/components/Common/uniforms/AddressField/utils.js.map +1 -0
- package/tmp/client/components/Common/uniforms/DateField.js +31 -0
- package/tmp/client/components/Common/uniforms/DateField.js.map +1 -0
- package/tmp/client/components/Common/uniforms/DateTimeField.js +44 -0
- package/tmp/client/components/Common/uniforms/DateTimeField.js.map +1 -0
- package/tmp/client/components/Common/uniforms/RichTextField/RichTextField.js +115 -0
- package/tmp/client/components/Common/uniforms/RichTextField/RichTextField.js.map +1 -0
- package/tmp/client/components/Common/uniforms/RichTextField/addMention.js +17 -0
- package/tmp/client/components/Common/uniforms/RichTextField/addMention.js.map +1 -0
- package/tmp/client/components/Common/uniforms/SocialField.js +37 -0
- package/tmp/client/components/Common/uniforms/SocialField.js.map +1 -0
- package/tmp/client/components/Common/uniforms/TableIdField.js +27 -0
- package/tmp/client/components/Common/uniforms/TableIdField.js.map +1 -0
- package/tmp/client/components/Location/Marker.js +24 -0
- package/tmp/client/components/Location/Marker.js.map +1 -0
- package/tmp/lib/actions/AddReferralSchema.js +27 -0
- package/tmp/lib/actions/AddReferralSchema.js.map +1 -0
- package/tmp/lib/actions/AutoMatchSchema.js +12 -0
- package/tmp/lib/actions/AutoMatchSchema.js.map +1 -0
- package/tmp/lib/actions/CampaignRefresh.js +12 -0
- package/tmp/lib/actions/CampaignRefresh.js.map +1 -0
- package/tmp/lib/actions/ChangeFamilyVisit.js +45 -0
- package/tmp/lib/actions/ChangeFamilyVisit.js.map +1 -0
- package/tmp/lib/actions/ContactFormSchema.js +38 -0
- package/tmp/lib/actions/ContactFormSchema.js.map +1 -0
- package/tmp/lib/actions/DeleteSchema.js +12 -0
- package/tmp/lib/actions/DeleteSchema.js.map +1 -0
- package/tmp/lib/actions/GroupFamilyStatus.js +43 -0
- package/tmp/lib/actions/GroupFamilyStatus.js.map +1 -0
- package/tmp/lib/actions/NotificationPopUpSchema.js +30 -0
- package/tmp/lib/actions/NotificationPopUpSchema.js.map +1 -0
- package/tmp/lib/actions/OneId.js +12 -0
- package/tmp/lib/actions/OneId.js.map +1 -0
- package/tmp/lib/actions/PaySchema.js +32 -0
- package/tmp/lib/actions/PaySchema.js.map +1 -0
- package/tmp/lib/actions/PaymentNotificationSchema.js +33 -0
- package/tmp/lib/actions/PaymentNotificationSchema.js.map +1 -0
- package/tmp/lib/actions/PlacementGuestFamilySchema.js +10 -0
- package/tmp/lib/actions/PlacementGuestFamilySchema.js.map +1 -0
- package/tmp/lib/actions/PlacementGuestMoveSchema.js +14 -0
- package/tmp/lib/actions/PlacementGuestMoveSchema.js.map +1 -0
- package/tmp/lib/actions/PlacementGuestStatusSchema.js +8 -0
- package/tmp/lib/actions/PlacementGuestStatusSchema.js.map +1 -0
- package/tmp/lib/actions/PlacementStatusSchema.js +33 -0
- package/tmp/lib/actions/PlacementStatusSchema.js.map +1 -0
- package/tmp/lib/actions/ReconfirmSchema.js +85 -0
- package/tmp/lib/actions/ReconfirmSchema.js.map +1 -0
- package/tmp/lib/actions/ReferralAddress.js +43 -0
- package/tmp/lib/actions/ReferralAddress.js.map +1 -0
- package/tmp/lib/actions/SendCommunicationSchema.js +26 -0
- package/tmp/lib/actions/SendCommunicationSchema.js.map +1 -0
- package/tmp/lib/actions/SendPreview.js +9 -0
- package/tmp/lib/actions/SendPreview.js.map +1 -0
- package/tmp/lib/actions/TranslationSchema.js +9 -0
- package/tmp/lib/actions/TranslationSchema.js.map +1 -0
- package/tmp/lib/actions/UploaderSchema.js +11 -0
- package/tmp/lib/actions/UploaderSchema.js.map +1 -0
- package/tmp/lib/actions/index.js +24 -0
- package/tmp/lib/actions/index.js.map +1 -0
- package/tmp/lib/constants.js +452 -0
- package/tmp/lib/constants.js.map +1 -0
- package/tmp/lib/forms/spans.js +12 -0
- package/tmp/lib/forms/spans.js.map +1 -0
- package/tmp/lib/schemas/Configuration/Locale.js +89 -0
- package/tmp/lib/schemas/Configuration/Locale.js.map +1 -0
- package/tmp/lib/schemas/Template.js +76 -0
- package/tmp/lib/schemas/Template.js.map +1 -0
- package/tmp/lib/schemas/utils.js +39 -0
- package/tmp/lib/schemas/utils.js.map +1 -0
- package/tmp/lib/utils.js +127 -0
- package/tmp/lib/utils.js.map +1 -0
- package/tmp/server/generated/prisma.js +52293 -0
- package/tmp/server/generated/prisma.js.map +1 -0
- package/src/Action/CustomAction.js +0 -108
- package/src/Action/CustomAction.js.map +0 -1
- package/src/Errors/TableInstanceNotFound.js +0 -28
- package/src/Errors/TableInstanceNotFound.js.map +0 -1
- package/src/Errors/UniqueActionError.js +0 -31
- package/src/Errors/UniqueActionError.js.map +0 -1
- package/src/Mandarina.js +0 -58
- package/src/Mandarina.js.map +0 -1
- package/src/Table/Table.js +0 -424
- package/src/Table/Table.js.map +0 -1
- package/src/Table/utils.js +0 -0
- package/src/index.js +0 -16
- package/src/index.js.map +0 -1
package/build/cli/index.js
CHANGED
|
@@ -5,6 +5,8 @@ var createProject_1 = require("./createProject");
|
|
|
5
5
|
var watch_1 = require("./watch");
|
|
6
6
|
var deploy_1 = require("./deploy");
|
|
7
7
|
var genFiles_1 = require("./gen-files/genFiles");
|
|
8
|
+
var prisma2_1 = require("./gen-files/prisma2");
|
|
9
|
+
console.log('cesar');
|
|
8
10
|
//@ts-ignore
|
|
9
11
|
var _a = process.argv, nodeDir = _a[0], dir = _a[1], cmd = _a[2], args = _a.slice(3);
|
|
10
12
|
switch (cmd) {
|
|
@@ -15,6 +17,9 @@ switch (cmd) {
|
|
|
15
17
|
case 'gen-files':
|
|
16
18
|
genFiles_1.genFile();
|
|
17
19
|
break;
|
|
20
|
+
case 'gen-prisma2':
|
|
21
|
+
prisma2_1.genFile();
|
|
22
|
+
break;
|
|
18
23
|
case 'deploy':
|
|
19
24
|
deploy_1.deploy();
|
|
20
25
|
break;
|
package/build/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAC9C,iCAA8B;AAC9B,mCAAgC;AAChC,iDAA6C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAC9C,iCAA8B;AAC9B,mCAAgC;AAChC,iDAA6C;AAC7C,+CAA0D;AAE1D,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AAEpB,YAAY;AACN,IAAA,iBAA2C,EAA1C,eAAO,EAAE,WAAG,EAAE,WAAG,EAAE,kBAAuB,CAAA;AAEjD,QAAQ,GAAG,EAAE;IACX,KAAK,QAAQ;QACX,IAAM,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,WAAW,CAAA;QAC9C,6BAAa,CAAC,OAAO,CAAC,CAAA;QACtB,MAAK;IACP,KAAK,WAAW;QACd,kBAAO,EAAE,CAAA;QACT,MAAM;IACR,KAAK,aAAa;QAChB,iBAAU,EAAE,CAAA;QACZ,MAAM;IACR,KAAK,QAAQ;QACX,eAAM,EAAE,CAAA;QACR,MAAM;IACR,KAAK,OAAO;QACV,aAAK,EAAE,CAAA;QACP,MAAM;IACR,KAAK,SAAS;QACZ,OAAO,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAA;QAC5D,MAAK;IACP;QACE,OAAO,CAAC,IAAI,CAAC,aAAW,GAAG,gFAAsE,CAAC,CAAA;CACrG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8EE"}
|
package/build/cli/utils.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare const getConfig: () => ConfigInterface;
|
|
2
2
|
export interface ConfigInterface {
|
|
3
|
+
database: {
|
|
4
|
+
url: string;
|
|
5
|
+
};
|
|
3
6
|
prisma: {
|
|
4
7
|
port: string;
|
|
5
8
|
host: string;
|
|
@@ -21,5 +24,6 @@ export interface ConfigDirInterface {
|
|
|
21
24
|
actions?: string[];
|
|
22
25
|
generated: string;
|
|
23
26
|
prisma: string;
|
|
27
|
+
prisma2: string;
|
|
24
28
|
}
|
|
25
29
|
export declare const loadSchemas: (dir: ConfigDirInterface) => void;
|
package/build/cli/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/cli/utils.ts"],"names":[],"mappings":";;;;;AAAA,0CAAoB;AACpB,8CAAwB;AAEX,QAAA,SAAS,GAAG;IACrB,IAAI,OAAO,CAAA;IACX,IAAI;QACA,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC,CAAA;KAChF;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,KAAK,CAAC,gGAAgG,CAAC,CAAA;KAChH;IACD,IAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAElC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,CAAC,gDAAgD,CAAC,CAAA;KAChE;IACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9F,MAAM,KAAK,CAAC,iFAAiF,CAAC,CAAA;KACjG;IACD,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QAC1D,MAAM,KAAK,CAAC,kDAAkD,CAAC,CAAA;KAClE;IACD,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QACxD,MAAM,KAAK,CAAC,iDAAiD,CAAC,CAAA;KACjE;IACD,IAAI,CAAC,MAAM,CAAC,G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AO,CAAC,UAAC,MAAM;QACnB,IAAM,OAAO,GAAW,YAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;YACtC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;YACxC,OAAO,CAAC,MAAM,CAAC,CAAA;SAClB;IACL,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK;QACjB,IAAM,OAAO,GAAW,YAAE,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvD,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;YACrC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAA;YACtC,OAAO,CAAC,KAAK,CAAC,CAAA;SACjB;IACL,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;QACnB,IAAM,OAAO,GAAW,YAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;YACrC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;YACxC,OAAO,CAAC,MAAM,CAAC,CAAA;SAClB;IACL,CAAC,CAAC,CAAA;AACN,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {ErrorFromServerMapper, Schema} from "mandarina/build/Schema/Schema";
|
|
1
|
+
import {ErrorFromServerMapper, Permission, Schema} from "mandarina/build/Schema/Schema";
|
|
2
2
|
import {TableInstanceNotFound} from "../Errors/TableInstanceNotFound";
|
|
3
3
|
import {UniqueActionError} from "../Errors/UniqueActionError";
|
|
4
|
-
|
|
5
|
-
import {Permission} from "mandarina/build/Schema/Schema";
|
|
6
4
|
import Mandarina from "../Mandarina";
|
|
7
|
-
|
|
5
|
+
import {Hook} from "../Table/Table";
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
export class CustomAction {
|
|
@@ -15,7 +13,10 @@ export class CustomAction {
|
|
|
15
13
|
public name: string;
|
|
16
14
|
public options: ActionOptions
|
|
17
15
|
public actions: ActionInterface
|
|
18
|
-
|
|
16
|
+
protected static hook: Hook
|
|
17
|
+
static setGlobalHook = (hook: Hook) => {
|
|
18
|
+
CustomAction.hook = hook
|
|
19
|
+
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
*
|
|
@@ -73,6 +74,13 @@ export class CustomAction {
|
|
|
73
74
|
console.log('*****************************************************************************')
|
|
74
75
|
//throw new Error(`Action "${action}" not allowed for this user`)
|
|
75
76
|
}
|
|
77
|
+
if (CustomAction.hook) {
|
|
78
|
+
context.schemaName= this.name
|
|
79
|
+
context.name= action
|
|
80
|
+
await CustomAction.hook(_, args, context, info)
|
|
81
|
+
delete context.schemaName
|
|
82
|
+
delete context.name
|
|
83
|
+
}
|
|
76
84
|
return await actions[action].action(_, args, context, info)
|
|
77
85
|
|
|
78
86
|
};
|
package/src/Table/Table.ts
CHANGED
|
@@ -30,7 +30,11 @@ export class Table {
|
|
|
30
30
|
public schema: Schema;
|
|
31
31
|
public name: string;
|
|
32
32
|
public options: TableSchemaOptions & TableShapeOptions;
|
|
33
|
+
protected static hooks: Hooks= {}
|
|
33
34
|
|
|
35
|
+
static setGlobalHooks = (hooks: Hooks) => {
|
|
36
|
+
Table.hooks = hooks
|
|
37
|
+
}
|
|
34
38
|
|
|
35
39
|
constructor(schema: Schema, tableOptions?: TableShapeOptions) {
|
|
36
40
|
Table.instances = Table.instances || {};
|
|
@@ -88,14 +92,15 @@ export class Table {
|
|
|
88
92
|
//Insert where option in to the query
|
|
89
93
|
// static dotConcat = (a: string | undefined, b: string) => a ? `${a}.${b}` : b;
|
|
90
94
|
getDefaultActions(type: operationType) {
|
|
95
|
+
console.log('getDefaultActions22')
|
|
91
96
|
// OperationName for query is user or users, for mutation are createUser, updateUser ....
|
|
92
97
|
const operationNames: string[] = Object.values(this.schema.names[type]);
|
|
93
98
|
const resultResolvers: { [resolverName: string]: (_: any, args: any, context: Context, info: any) => void } = {};
|
|
94
99
|
operationNames.forEach((operationName: string) => {
|
|
95
100
|
if (!this.shouldHasManyUpdate()) return
|
|
96
101
|
resultResolvers[operationName] = async (_: any, args: any = {}, context: Context, info: GraphQLResolveInfo) => {
|
|
102
|
+
|
|
97
103
|
context.originalArgs=args
|
|
98
|
-
bm()
|
|
99
104
|
const user = await Mandarina.config.getUser(context)
|
|
100
105
|
const subOperationName: ActionType | string = operationName.substr(0, 6)
|
|
101
106
|
const action: ActionType = <ActionType>(['create', 'update', 'delete'].includes(subOperationName) ? subOperationName : 'read')
|
|
@@ -103,6 +108,8 @@ export class Table {
|
|
|
103
108
|
const capitalizedAction = capitalize(action)
|
|
104
109
|
await this.callHook(this.name, 'beforeValidate', _, args, context, info);
|
|
105
110
|
const isSingleMutation = operationName === this.schema.names.mutation.update || operationName === this.schema.names.mutation.create
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
|
|
106
113
|
let {query, queryString, fields} = this.insertWhereIntoInfo(info, user, isSingleMutation, action, operationName)
|
|
107
114
|
if (type === 'mutation') {
|
|
108
115
|
// if (errors.length > 0) {
|
|
@@ -182,7 +189,6 @@ export class Table {
|
|
|
182
189
|
context.result = result
|
|
183
190
|
await this.callHook(this.name, 'afterQuery', _, args, context, info);
|
|
184
191
|
}
|
|
185
|
-
bm(`${operationName} ${type} over ${this.name}`)
|
|
186
192
|
return result;
|
|
187
193
|
}
|
|
188
194
|
});
|
|
@@ -190,6 +196,7 @@ export class Table {
|
|
|
190
196
|
}
|
|
191
197
|
|
|
192
198
|
insertWhereIntoInfo = (info: GraphQLResolveInfo, user: UserType | null| undefined, isSingleMutation = false, action: ActionType, operationName: string) => {
|
|
199
|
+
console.log('insertWhereIntoInfo')
|
|
193
200
|
const field: string[] = []
|
|
194
201
|
const fields = new Set<string>()
|
|
195
202
|
let required = false
|
|
@@ -228,10 +235,13 @@ export class Table {
|
|
|
228
235
|
originalWhereString = print(originalWhereObj.value)
|
|
229
236
|
required = true
|
|
230
237
|
}
|
|
238
|
+
console.log('where',where)
|
|
231
239
|
const newWhereString = stringifyObject(where, {singleQuotes: false})
|
|
240
|
+
console.log('newWhereString',newWhereString)
|
|
232
241
|
let finalWhereString = originalWhereString ? `{AND:[${originalWhereString},${newWhereString}]}` : newWhereString
|
|
233
242
|
if (originalWhereObj) {
|
|
234
243
|
originalWhereObj.value = parseValue(new Source(finalWhereString))
|
|
244
|
+
console.log('originalWhereObj',originalWhereObj)
|
|
235
245
|
} else {
|
|
236
246
|
clone.arguments.push({
|
|
237
247
|
kind: 'Argument',
|
|
@@ -281,6 +291,7 @@ export class Table {
|
|
|
281
291
|
let prefix = ''
|
|
282
292
|
if (name.indexOf('before') === 0) prefix = 'before'
|
|
283
293
|
if (name.indexOf('after') === 0) prefix = 'after'
|
|
294
|
+
const globalHookHandler = Table.hooks[name];
|
|
284
295
|
const hookHandler = this.options.hooks && this.options.hooks[name];
|
|
285
296
|
if ( args.data && prefix) {
|
|
286
297
|
const fields = Object.keys( args.data)
|
|
@@ -320,6 +331,11 @@ export class Table {
|
|
|
320
331
|
}
|
|
321
332
|
}
|
|
322
333
|
}
|
|
334
|
+
if (globalHookHandler) {
|
|
335
|
+
context.schemaName=schemaName
|
|
336
|
+
context.name=name
|
|
337
|
+
await globalHookHandler(_, args, context, info);
|
|
338
|
+
}
|
|
323
339
|
if (hookHandler) {
|
|
324
340
|
await hookHandler(_, args, context, info);
|
|
325
341
|
}
|
|
@@ -374,25 +390,26 @@ export interface Hook {
|
|
|
374
390
|
|
|
375
391
|
export type operationType = "mutation" | "query"
|
|
376
392
|
|
|
393
|
+
export type Hooks={
|
|
394
|
+
beforeValidate?: Hook
|
|
395
|
+
afterValidate?: Hook
|
|
396
|
+
validationFailed?: Hook
|
|
397
|
+
beforeCreate?: Hook
|
|
398
|
+
beforeDelete?: Hook
|
|
399
|
+
beforeUpdate?: Hook
|
|
400
|
+
beforeSave?: Hook
|
|
401
|
+
afterCreate?: Hook
|
|
402
|
+
afterDelete?: Hook
|
|
403
|
+
afterUpdate?: Hook
|
|
404
|
+
|
|
405
|
+
// Query operation hooks
|
|
406
|
+
beforeQuery?: Hook
|
|
407
|
+
afterQuery?: Hook
|
|
408
|
+
}
|
|
377
409
|
|
|
378
410
|
export interface TableSchemaOptions {
|
|
379
411
|
virtual?: boolean
|
|
380
|
-
hooks?:
|
|
381
|
-
beforeValidate?: Hook
|
|
382
|
-
afterValidate?: Hook
|
|
383
|
-
validationFailed?: Hook
|
|
384
|
-
beforeCreate?: Hook
|
|
385
|
-
beforeDelete?: Hook
|
|
386
|
-
beforeUpdate?: Hook
|
|
387
|
-
beforeSave?: Hook
|
|
388
|
-
afterCreate?: Hook
|
|
389
|
-
afterDelete?: Hook
|
|
390
|
-
afterUpdate?: Hook
|
|
391
|
-
|
|
392
|
-
// Query operation hooks
|
|
393
|
-
beforeQuery?: Hook
|
|
394
|
-
afterQuery?: Hook
|
|
395
|
-
}
|
|
412
|
+
hooks?: Hooks
|
|
396
413
|
filters?: Filter[]
|
|
397
414
|
}
|
|
398
415
|
|
|
@@ -406,7 +423,7 @@ export interface TableShapeOptions extends TableSchemaOptions {
|
|
|
406
423
|
}
|
|
407
424
|
|
|
408
425
|
|
|
409
|
-
type HookName =
|
|
426
|
+
export type HookName =
|
|
410
427
|
'beforeValidate'
|
|
411
428
|
| 'afterValidate'
|
|
412
429
|
| 'validationFailed'
|
|
@@ -419,10 +436,10 @@ type HookName =
|
|
|
419
436
|
| 'beforeQuery'
|
|
420
437
|
| 'afterQuery'
|
|
421
438
|
|
|
422
|
-
let time = new Date().getTime()
|
|
439
|
+
// let time = new Date().getTime()
|
|
423
440
|
|
|
424
|
-
export function bm(description = '',...args:any) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
441
|
+
// export function bm(description = '',...args:any) {
|
|
442
|
+
// description && console.info(description,...args, new Date().getTime() - time)
|
|
443
|
+
// time = new Date().getTime()
|
|
444
|
+
//
|
|
445
|
+
// }
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {getConfig, loadSchemas} from "../utils";
|
|
2
|
+
import {createDir} from "./genFilesUtils";
|
|
3
|
+
import {Table} from "../..";
|
|
4
|
+
import {Schema} from "mandarina";
|
|
5
|
+
import {isRequired} from "mandarina/build/Schema/utils";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import {FieldDefinition} from "mandarina/build/Schema/Schema";
|
|
9
|
+
|
|
10
|
+
const prisma2Models: { [schemaName: string]: { [fieldName: string]: string } } = {}
|
|
11
|
+
const processed: { [schemaName: string]: { [schemaName: string]: { [fieldName: string]: true } } } = {}
|
|
12
|
+
const processedSubSchemas: string[] = []
|
|
13
|
+
export const genFile = () => {
|
|
14
|
+
const config = getConfig()
|
|
15
|
+
loadSchemas(config.dir)
|
|
16
|
+
createDir(config.dir.prisma2)
|
|
17
|
+
for (const schemaName in Table.instances) {
|
|
18
|
+
const schema = Schema.getInstance(schemaName)
|
|
19
|
+
getPrisma2Model(schema)
|
|
20
|
+
}
|
|
21
|
+
let prisma = `generator client {
|
|
22
|
+
provider = "prisma-client-js"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
datasource db {
|
|
26
|
+
provider = "postgresql"
|
|
27
|
+
url = env("DATABASE_URL")
|
|
28
|
+
}
|
|
29
|
+
`
|
|
30
|
+
Object.keys(prisma2Models).forEach(modelName => {
|
|
31
|
+
const model = prisma2Models[modelName]
|
|
32
|
+
prisma += `model ${modelName} {\n `
|
|
33
|
+
Object.keys(model).forEach(fieldName => {
|
|
34
|
+
const field = model[fieldName]
|
|
35
|
+
prisma += `\t${fieldName} ${field}\n`
|
|
36
|
+
})
|
|
37
|
+
prisma += `}\n\n`
|
|
38
|
+
})
|
|
39
|
+
const prismaDir = path.join(process.cwd(), config.dir.prisma2,)
|
|
40
|
+
const fileAbs = `${prismaDir}/schema.prisma`;
|
|
41
|
+
fs.writeFileSync(fileAbs, prisma);
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const getPrisma2Model = (schema: Schema) => {
|
|
46
|
+
prisma2Models[schema.name] = prisma2Models[schema.name] || {}
|
|
47
|
+
for (const key of schema.keys) {
|
|
48
|
+
if (key === 'id') {
|
|
49
|
+
c++
|
|
50
|
+
prisma2Models[schema.name].id = `String @id @default(cuid()) //`;
|
|
51
|
+
} else {
|
|
52
|
+
const fieldDefinition = schema.getPathDefinition(key)
|
|
53
|
+
let required = fieldDefinition.isArray || isRequired(fieldDefinition)
|
|
54
|
+
const fieldType = getGraphQLType(fieldDefinition, key, required);
|
|
55
|
+
const unique = fieldDefinition.table.unique ? '@unique' : ''
|
|
56
|
+
let createdAt = '', updatedAt = ''
|
|
57
|
+
let defaultValue = ''
|
|
58
|
+
if (fieldDefinition.table.default !== undefined) {
|
|
59
|
+
const wrapper = (fieldDefinition.type === String) ? '"' : ''
|
|
60
|
+
defaultValue = `@default(${wrapper}${fieldDefinition.table.default}${wrapper})`
|
|
61
|
+
}
|
|
62
|
+
if ((fieldDefinition.table.createdAt === true || (fieldDefinition.table.createdAt !== false && key === 'createdAt'))) {
|
|
63
|
+
createdAt = `@default(now())`
|
|
64
|
+
}
|
|
65
|
+
if ((fieldDefinition.table.updatedAt === true || (fieldDefinition.table.updatedAt !== false && key === 'updatedAt'))) {
|
|
66
|
+
createdAt = `@default(now())`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (fieldDefinition.table.default !== undefined) {
|
|
70
|
+
const wrapper = (fieldDefinition.type === String) ? '"' : ''
|
|
71
|
+
defaultValue = `@default(${wrapper}${fieldDefinition.table.default}${wrapper})`
|
|
72
|
+
}
|
|
73
|
+
if (fieldDefinition.isTable) {
|
|
74
|
+
getPrismaModelAModelB(schema, fieldDefinition)
|
|
75
|
+
if (!processedSubSchemas.includes(fieldDefinition.type) ) {
|
|
76
|
+
processedSubSchemas.push(fieldDefinition.type)
|
|
77
|
+
getPrisma2Model(Schema.getInstance(fieldDefinition.type))
|
|
78
|
+
}
|
|
79
|
+
}else{
|
|
80
|
+
prisma2Models[schema.name][key] = `${fieldType} ${unique} ${createdAt} ${updatedAt} ${defaultValue}`;
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}// end for
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let c=0
|
|
88
|
+
const getPrismaModelAModelB = (schema: Schema, fieldDefinition: FieldDefinition) => {
|
|
89
|
+
if (!fieldDefinition.isTable) {
|
|
90
|
+
throw new Error(`Relation must be an array`)
|
|
91
|
+
}
|
|
92
|
+
processed[schema.name] = processed[schema.name] || {}
|
|
93
|
+
processed[schema.name][fieldDefinition.type] = processed[schema.name][fieldDefinition.type] || {}
|
|
94
|
+
prisma2Models[fieldDefinition.type] = prisma2Models[fieldDefinition.type] || {}
|
|
95
|
+
prisma2Models[schema.name] = prisma2Models[schema.name] || {}
|
|
96
|
+
c++
|
|
97
|
+
const childSchema = Schema.getInstance(fieldDefinition.type)
|
|
98
|
+
const children = childSchema.keys.filter(fieldName => childSchema.getPathDefinition(fieldName).type === schema.name)
|
|
99
|
+
|
|
100
|
+
if (!processed[schema.name][fieldDefinition.type][fieldDefinition.key]) {
|
|
101
|
+
if (schema.name === fieldDefinition.type) {
|
|
102
|
+
if (fieldDefinition.isArray) {
|
|
103
|
+
throw new Error(`DO THIS`)
|
|
104
|
+
}else{
|
|
105
|
+
if (fieldDefinition.isArray) {
|
|
106
|
+
throw new Error(`DO THIS`)
|
|
107
|
+
}else{
|
|
108
|
+
const child = schema.getPathDefinition(fieldDefinition.key)
|
|
109
|
+
|
|
110
|
+
if (getRelation(fieldDefinition)!==getRelation(child)){
|
|
111
|
+
throw new Error(`Relation must be the same`)
|
|
112
|
+
}
|
|
113
|
+
const relation = getRelationName(fieldDefinition, child) || `${schema.name}To${schema.name}`
|
|
114
|
+
const fields=`p2${fieldDefinition.key}Id`
|
|
115
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${schema.name}? ${buildRelation(relation, fields)} //SELF: 1 - 1 ((${c}))`;
|
|
116
|
+
prisma2Models[schema.name][fields] = `String? @unique //SELF: 1 - 1 ((${c}))`;
|
|
117
|
+
prisma2Models[schema.name][`p2Predecessor${schema.name}`] = `${schema.name}? ${buildRelation(relation)}//SELF: 1 - 1 ((${c}))`;
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
if (children.length === 0) {
|
|
123
|
+
const relation = getRelationName(fieldDefinition)
|
|
124
|
+
if (fieldDefinition.isArray) {
|
|
125
|
+
//relation many to one
|
|
126
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}[] ${buildRelation(relation)}//CREATE: n - 1 ((${c}))`;
|
|
127
|
+
const fields=`p2${relation}${schema.name}Id`
|
|
128
|
+
prisma2Models[fieldDefinition.type][`p2${relation}${schema.name}`] = `${schema.name}? ${buildRelation(relation, fields)} //=>CREATE: n - 1 ((${c}))`;
|
|
129
|
+
prisma2Models[fieldDefinition.type][fields] = `String? //=>CREATE: 1 - n ((${c}))`;
|
|
130
|
+
} else {
|
|
131
|
+
if (!fieldDefinition.table?.relation?.type) {
|
|
132
|
+
throw new Error(`Relation must be defined ONE_TO_ONE || ONE_TO_MANY- ${schema.name}.${fieldDefinition.key}`)
|
|
133
|
+
}
|
|
134
|
+
if (fieldDefinition.table?.relation?.type === 'ONE_TO_ONE') {
|
|
135
|
+
const fields=`p2${relation}${schema.name}Id`
|
|
136
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}? ${buildRelation(relation)}//INLINE : 1 - 1 ((${c}))`;
|
|
137
|
+
prisma2Models[fieldDefinition.type][`p2${relation}${schema.name}`] = `${schema.name}? ${buildRelation(relation,fields)} //=>INLINE: 1 - 1 ((${c}))`;
|
|
138
|
+
prisma2Models[fieldDefinition.type][fields] = `String? @unique //=>INLINE: 1 - 1 ((${c}))`;
|
|
139
|
+
}else if (fieldDefinition.table?.relation?.type === 'ONE_TO_MANY') {
|
|
140
|
+
const fields=`p2${relation}${fieldDefinition.type}Id`
|
|
141
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}? ${buildRelation(relation,fields)}//CREATE: 1 - n ((${c}))`;
|
|
142
|
+
prisma2Models[schema.name][fields] = `String? //=>CREATE: 1 - n ((${c}))`;
|
|
143
|
+
prisma2Models[fieldDefinition.type][`p2${relation}${schema.name}`] = `${schema.name}[] ${buildRelation(relation)} //=>CREATE: 1 - n ((${c}))`;
|
|
144
|
+
}else{
|
|
145
|
+
throw new Error(`many to one does no exists for create - ${schema.name}.${fieldDefinition.key}`)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} else if (children.length >= 1) {
|
|
149
|
+
let child: FieldDefinition
|
|
150
|
+
if (children.length === 1) {
|
|
151
|
+
child = childSchema.getPathDefinition(children[0])
|
|
152
|
+
} else {
|
|
153
|
+
const childName = children.find(childName => getRelation(childSchema.getPathDefinition(childName)) === getRelation(fieldDefinition))
|
|
154
|
+
if (!childName) {
|
|
155
|
+
throw new Error(`Relation not found111`)
|
|
156
|
+
}
|
|
157
|
+
child = childSchema.getPathDefinition(childName)
|
|
158
|
+
}
|
|
159
|
+
if (!child) {
|
|
160
|
+
throw new Error(`Relation not found222`)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (child.isArray) { // means that the parent is the array (because fieldDefinition.isArray is array then child is the gran children which is really the parent)
|
|
164
|
+
const relation = getRelationName(fieldDefinition,child)
|
|
165
|
+
if (fieldDefinition.isArray) {
|
|
166
|
+
//relation many to many
|
|
167
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}[] ${buildRelation(relation)} //n - n ((${c}))`;
|
|
168
|
+
prisma2Models[fieldDefinition.type][child.key] = `${child.type}[] ${buildRelation(relation)} //=>n - n ((${c}))`;
|
|
169
|
+
} else {
|
|
170
|
+
//relation one to many
|
|
171
|
+
const relation = getRelationName(fieldDefinition,child)
|
|
172
|
+
const fields=`p2${relation}${fieldDefinition.type}Id`
|
|
173
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}? ${buildRelation(relation, fields)} //n - 1 ((${c}))`;
|
|
174
|
+
prisma2Models[schema.name][fields] = `String? //n - 1 ((${c}))`;
|
|
175
|
+
prisma2Models[fieldDefinition.type][child.key] = `${schema.name} [] ${buildRelation(relation)}//=>n - 1 ((${c}))`;
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
const relation = getRelationName(fieldDefinition,child)
|
|
180
|
+
if (fieldDefinition.isArray) {
|
|
181
|
+
//relation many to many
|
|
182
|
+
const fields=`p2${relation}${schema.name}Id`
|
|
183
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}[] ${buildRelation(relation)}//1 - n ((${c}))`;
|
|
184
|
+
prisma2Models[fieldDefinition.type][child.key] = `${schema.name}? ${buildRelation(relation,fields)} //=>n - 1 ((${c}))`;
|
|
185
|
+
prisma2Models[fieldDefinition.type][fields] = `String? //=>n - 1 ((${c}))`;
|
|
186
|
+
|
|
187
|
+
} else {
|
|
188
|
+
if (!fieldDefinition.table?.relation?.owner && !child.table?.relation?.owner) {
|
|
189
|
+
throw new Error(`Relation must be defined a owner - ${schema.name}.${fieldDefinition.key}`)
|
|
190
|
+
}
|
|
191
|
+
if (fieldDefinition.table?.relation?.owner && child.table?.relation?.owner) {
|
|
192
|
+
throw new Error(`Relation booth can not be a owner - ${schema.name}.${fieldDefinition.key}`)
|
|
193
|
+
}
|
|
194
|
+
if (fieldDefinition.table?.relation?.owner) {
|
|
195
|
+
const fields = `p2${relation}${schema.name}Id`
|
|
196
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}? ${buildRelation(relation)}//OWNER 1 - 1 ((${c}))`;
|
|
197
|
+
prisma2Models[fieldDefinition.type][child.key] = `${schema.name}? ${buildRelation(relation, fields)} //OWNER =>1 - 1 ((${c}))`;
|
|
198
|
+
prisma2Models[fieldDefinition.type][fields] = `String? @unique //OWNER =>1 - 1 ((${c}))`;
|
|
199
|
+
}else{
|
|
200
|
+
const fields = `p2${relation}${fieldDefinition.type}Id`
|
|
201
|
+
prisma2Models[schema.name][fieldDefinition.key] = `${fieldDefinition.type}? ${buildRelation(relation, fields)}//OWNED 1 - 1 ((${c}))`;
|
|
202
|
+
prisma2Models[schema.name][fields] = `String? @unique ${buildRelation(relation)} //OWNED =>1 - 1 ((${c}))`;
|
|
203
|
+
prisma2Models[fieldDefinition.type][child.key] = `${child.type}? //OWNED =>1 - 1 ((${c}))`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
processed[fieldDefinition.type] = processed[fieldDefinition.type] || {}
|
|
208
|
+
processed[fieldDefinition.type][schema.name] = processed[fieldDefinition.type][schema.name] || {}
|
|
209
|
+
processed[fieldDefinition.type][schema.name][child.key] = true
|
|
210
|
+
} else {
|
|
211
|
+
throw new Error(`Relation must be have name`)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
function getRelation(fieldDefinition: FieldDefinition) {
|
|
220
|
+
if (!fieldDefinition.table.relation) return ''
|
|
221
|
+
if (typeof fieldDefinition.table.relation === 'string') {
|
|
222
|
+
return fieldDefinition.table.relation
|
|
223
|
+
}
|
|
224
|
+
return fieldDefinition.table.relation.name || ''
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const getGraphQLType = (def: FieldDefinition, key: string, required: boolean): string => {
|
|
228
|
+
const optional = !def.isArray && !required ? '?' : ''
|
|
229
|
+
switch (true) {
|
|
230
|
+
case (!def.isArray && !def.isTable && def.type.name === 'String'):
|
|
231
|
+
return `String${optional}`;
|
|
232
|
+
|
|
233
|
+
case (!def.isArray && !def.isTable && def.type.name === 'Boolean'):
|
|
234
|
+
return `Boolean${optional}`;
|
|
235
|
+
|
|
236
|
+
case (!def.isArray && !def.isTable && def.type.name === 'Number'):
|
|
237
|
+
return `Float${optional}`;
|
|
238
|
+
|
|
239
|
+
case (!def.isArray && !def.isTable && def.type.name === 'Integer'):
|
|
240
|
+
return `Int${optional}`;
|
|
241
|
+
case (!def.isArray && !def.isTable && def.type.name === 'Date'):
|
|
242
|
+
return `DateTime${optional}`;
|
|
243
|
+
case (def.isArray && def.isTable):
|
|
244
|
+
return `${def.type}[]`
|
|
245
|
+
case (def.isArray && !def.isTable):
|
|
246
|
+
const scalarName = getGraphQLType({...def, isArray: false}, key, def.isArray && required)
|
|
247
|
+
return `${scalarName}[]`
|
|
248
|
+
default:
|
|
249
|
+
return def.type + optional;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function buildRelation(relation: string, fields?: string){
|
|
254
|
+
if (!relation && !fields) return ''
|
|
255
|
+
if (!relation) return `@relation(fields: [${fields}], references: [id])`
|
|
256
|
+
if (fields){
|
|
257
|
+
return `@relation("${relation}", fields: [${fields}], references: [id])`
|
|
258
|
+
}
|
|
259
|
+
return `@relation("${relation}")`
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const getRelationName = (def1: FieldDefinition, def2?:FieldDefinition) => {
|
|
264
|
+
const n1=getRelation(def1)
|
|
265
|
+
if (!def2){
|
|
266
|
+
if (!n1){
|
|
267
|
+
return ''
|
|
268
|
+
}
|
|
269
|
+
return n1
|
|
270
|
+
}
|
|
271
|
+
const n2=getRelation(def2)
|
|
272
|
+
if (n1!==n2){
|
|
273
|
+
throw new Error(`Relation name must be equal ${n1} ${n2}`)
|
|
274
|
+
}
|
|
275
|
+
if (!n1) return ""
|
|
276
|
+
return n1
|
|
277
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -3,6 +3,9 @@ import {createProject} from "./createProject";
|
|
|
3
3
|
import {watch} from "./watch";
|
|
4
4
|
import {deploy} from "./deploy";
|
|
5
5
|
import {genFile} from "./gen-files/genFiles";
|
|
6
|
+
import {genFile as genPrisma2} from "./gen-files/prisma2";
|
|
7
|
+
|
|
8
|
+
console.log('cesar')
|
|
6
9
|
|
|
7
10
|
//@ts-ignore
|
|
8
11
|
const [nodeDir, dir, cmd, ...args] = process.argv
|
|
@@ -15,6 +18,9 @@ switch (cmd) {
|
|
|
15
18
|
case 'gen-files':
|
|
16
19
|
genFile()
|
|
17
20
|
break;
|
|
21
|
+
case 'gen-prisma2':
|
|
22
|
+
genPrisma2()
|
|
23
|
+
break;
|
|
18
24
|
case 'deploy':
|
|
19
25
|
deploy()
|
|
20
26
|
break;
|
package/src/cli/utils.js
CHANGED
|
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadSchemas = exports.getConfig = void 0;
|
|
6
7
|
var fs_1 = __importDefault(require("fs"));
|
|
7
8
|
var path_1 = __importDefault(require("path"));
|
|
8
|
-
|
|
9
|
+
var getConfig = function () {
|
|
9
10
|
var rawData;
|
|
10
11
|
try {
|
|
11
12
|
rawData = fs_1.default.readFileSync(path_1.default.join(process.cwd(), 'mandarina.json'), 'utf8');
|
|
@@ -34,6 +35,7 @@ exports.getConfig = function () {
|
|
|
34
35
|
}
|
|
35
36
|
return (config);
|
|
36
37
|
};
|
|
38
|
+
exports.getConfig = getConfig;
|
|
37
39
|
var walkSync = function (dir, fileList) {
|
|
38
40
|
var files = fs_1.default.readdirSync(dir);
|
|
39
41
|
fileList = fileList || [];
|
|
@@ -49,7 +51,7 @@ var walkSync = function (dir, fileList) {
|
|
|
49
51
|
});
|
|
50
52
|
return fileList;
|
|
51
53
|
};
|
|
52
|
-
|
|
54
|
+
var loadSchemas = function (dir) {
|
|
53
55
|
var tables = [];
|
|
54
56
|
var schemas = [];
|
|
55
57
|
var actions = [];
|
|
@@ -88,4 +90,5 @@ exports.loadSchemas = function (dir) {
|
|
|
88
90
|
}
|
|
89
91
|
});
|
|
90
92
|
};
|
|
93
|
+
exports.loadSchemas = loadSchemas;
|
|
91
94
|
//# sourceMappingURL=utils.js.map
|
package/src/cli/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAoB;AACpB,8CAAwB;AAEjB,IAAM,SAAS,GAAG;IACrB,IAAI,OAAO,CAAA;IACX,IAAI;QACA,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC,CAAA;KAChF;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,KAAK,CAAC,gGAAgG,CAAC,CAAA;KAChH;IACD,IAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAElC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,CAAC,gDAAgD,CAAC,CAAA;KAChE;IACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9F,MAAM,KAAK,CAAC,iFAAiF,CAAC,CAAA;KACjG;IACD,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KA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AI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;YACrC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAA;YACtC,OAAO,CAAC,KAAK,CAAC,CAAA;SACjB;IACL,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;QACnB,IAAM,OAAO,GAAW,YAAE,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;YACrC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;YACxC,OAAO,CAAC,MAAM,CAAC,CAAA;SAClB;IACL,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAvCY,QAAA,WAAW,eAuCvB"}
|
package/src/cli/utils.ts
CHANGED
|
@@ -46,8 +46,11 @@ const walkSync = function (dir: string, fileList: string[]) {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export interface ConfigInterface {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
database: {
|
|
50
|
+
url: string,
|
|
51
|
+
}
|
|
52
|
+
prisma: {
|
|
53
|
+
port: string,
|
|
51
54
|
host: string,
|
|
52
55
|
database?: string,
|
|
53
56
|
stage?: string,
|
|
@@ -58,7 +61,7 @@ export interface ConfigInterface {
|
|
|
58
61
|
}
|
|
59
62
|
secret?: string
|
|
60
63
|
customSettings: {
|
|
61
|
-
[props:string]: any
|
|
64
|
+
[props: string]: any
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
|
|
@@ -68,6 +71,7 @@ export interface ConfigDirInterface {
|
|
|
68
71
|
actions?: string[]
|
|
69
72
|
generated: string
|
|
70
73
|
prisma: string
|
|
74
|
+
prisma2: string
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
export const loadSchemas = (dir: ConfigDirInterface) => {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("mandarina/build/Schema/utils");
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const utils_2 = require("../../../../lib/utils");
|
|
9
|
+
const ConfigurationContext_1 = require("../ConfigurationContext");
|
|
10
|
+
// @ts-ignore //TODO: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/27805
|
|
11
|
+
const CellDateTime = ConfigurationContext_1.withConfiguration(({ columnIndex, rowIndex, data, field, configuration }) => {
|
|
12
|
+
const dates = utils_1.get(data[rowIndex], field.split('.'));
|
|
13
|
+
return dates.map((d, i) => {
|
|
14
|
+
const [h, t] = utils_2.showDateTime(dates, configuration.locale.dateFormat).split(', ');
|
|
15
|
+
return react_1.default.createElement("span", { key: i },
|
|
16
|
+
h,
|
|
17
|
+
react_1.default.createElement("br", null),
|
|
18
|
+
t);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
exports.default = CellDateTime;
|
|
22
|
+
//# sourceMappingURL=CellDateTime.js.map
|