@fraym/crud 0.4.0 → 0.6.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/README.md +4 -2
- package/dist/cmd/crud.js +31 -9
- package/dist/config/config.js +0 -1
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -22,9 +22,11 @@ Use the `crud` cli command to automatically apply your crud schemas to the crud
|
|
|
22
22
|
Your type schemas have to match the glob you specify in the `CRUD_SCHEMA_GLOB` env variable (default: `./src/**/*.graphql`).
|
|
23
23
|
You can specify the address (and port) of the crud service instance you use in the `CRUD_SERVER_ADDRESS` env variable (default: `127.0.0.1:9000`).
|
|
24
24
|
|
|
25
|
+
You need to add a file that contains all built-in directives to your type schemas. The latest version of this file can be found [here](default.graphql).
|
|
26
|
+
|
|
25
27
|
### Config
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
Use a `.env` file or env variables to configure cte clients and the command:
|
|
28
30
|
|
|
29
31
|
```env
|
|
30
32
|
CRUD_SERVER_ADDRESS=127.0.0.1:9000
|
|
@@ -110,7 +112,7 @@ await client.delete("tenantId", "YourCrudType", "id");
|
|
|
110
112
|
### Get a single data element
|
|
111
113
|
|
|
112
114
|
The name of `YourCrudType` has to equal your type name in your schema (also in casing).
|
|
113
|
-
The `id` has to match the id of the data that you want to
|
|
115
|
+
The `id` has to match the id of the data that you want to get.
|
|
114
116
|
|
|
115
117
|
```typescript
|
|
116
118
|
const data = await client.getData("tenantId", "YourCrudType", "id");
|
package/dist/cmd/crud.js
CHANGED
|
@@ -34,18 +34,38 @@ run();
|
|
|
34
34
|
const getTypeDefinition = (schema) => {
|
|
35
35
|
const definitions = {};
|
|
36
36
|
schema.toConfig().types.forEach(t => {
|
|
37
|
-
|
|
38
|
-
if (((_a = t.astNode) === null || _a === void 0 ? void 0 : _a.kind) !== graphql_1.Kind.OBJECT_TYPE_DEFINITION || !(t instanceof graphql_1.GraphQLObjectType)) {
|
|
37
|
+
if (!(t instanceof graphql_1.GraphQLObjectType) && !(t instanceof graphql_1.GraphQLEnumType)) {
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
41
40
|
const name = t.toString();
|
|
42
41
|
if (definitions[name]) {
|
|
43
42
|
throw new Error(`duplicate definition for type "${name}" detected, try renaming one of them as they have to be uniquely named`);
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
if (t instanceof graphql_1.GraphQLObjectType) {
|
|
45
|
+
definitions[name] = getTypeDefinitionFromGraphQLObjectType(t);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (t instanceof graphql_1.GraphQLEnumType) {
|
|
49
|
+
definitions[name] = getTypeDefinitionFromGraphQLEnumType(t);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
46
52
|
});
|
|
47
53
|
return definitions;
|
|
48
54
|
};
|
|
55
|
+
const getTypeDefinitionFromGraphQLEnumType = (t) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const name = t.toString();
|
|
58
|
+
let enumValuesString = "";
|
|
59
|
+
(_b = (_a = t.astNode) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.forEach(value => {
|
|
60
|
+
enumValuesString += `\n\t${value.name.value}`;
|
|
61
|
+
});
|
|
62
|
+
const schema = `enum ${name} {${enumValuesString}\n}`;
|
|
63
|
+
return {
|
|
64
|
+
isCrudType: false,
|
|
65
|
+
nestedTypes: [],
|
|
66
|
+
schema,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
49
69
|
const getTypeDefinitionFromGraphQLObjectType = (t) => {
|
|
50
70
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
51
71
|
const isCrudType = (_c = (((_a = t.astNode) === null || _a === void 0 ? void 0 : _a.directives) &&
|
|
@@ -86,7 +106,7 @@ const getFieldStringAndNestedTypes = (f) => {
|
|
|
86
106
|
nestedTypes.push(nestedType);
|
|
87
107
|
}
|
|
88
108
|
return {
|
|
89
|
-
str: `\n${f.name.value}: ${typeString}${directivesString}`,
|
|
109
|
+
str: `\n\t${f.name.value}: ${typeString}${directivesString}`,
|
|
90
110
|
nestedTypes,
|
|
91
111
|
};
|
|
92
112
|
};
|
|
@@ -98,7 +118,8 @@ const getTypeData = (t) => {
|
|
|
98
118
|
name === "Float" ||
|
|
99
119
|
name === "ID" ||
|
|
100
120
|
name === "Boolean" ||
|
|
101
|
-
name === "Int"
|
|
121
|
+
name === "Int" ||
|
|
122
|
+
name === "DateTime"
|
|
102
123
|
? {
|
|
103
124
|
str: name,
|
|
104
125
|
}
|
|
@@ -183,23 +204,24 @@ const migrateSchemas = async (definitions, serverAddress) => {
|
|
|
183
204
|
typesToUpdate.push(existingName);
|
|
184
205
|
updateSchema += `\n${definitions[existingName].schema}`;
|
|
185
206
|
definitions[existingName].nestedTypes.forEach(nestedTypeName => {
|
|
186
|
-
if (nestedTypesToUpdate.indexOf(nestedTypeName) !== -1
|
|
207
|
+
if (nestedTypesToUpdate.indexOf(nestedTypeName) !== -1 ||
|
|
208
|
+
(definitions[nestedTypeName] && definitions[nestedTypeName].isCrudType)) {
|
|
187
209
|
return;
|
|
188
210
|
}
|
|
189
211
|
updateSchema += `\n${definitions[nestedTypeName].schema}`;
|
|
190
212
|
nestedTypesToUpdate.push(nestedTypeName);
|
|
191
213
|
});
|
|
192
|
-
delete definitions[existingName];
|
|
193
214
|
}
|
|
194
215
|
});
|
|
195
216
|
Object.keys(definitions).forEach(newName => {
|
|
196
|
-
if (!definitions[newName].isCrudType) {
|
|
217
|
+
if (!definitions[newName].isCrudType || existingTypeNames.includes(newName)) {
|
|
197
218
|
return;
|
|
198
219
|
}
|
|
199
220
|
typesToCreate.push(newName);
|
|
200
221
|
createSchema += `\n${definitions[newName].schema}`;
|
|
201
222
|
definitions[newName].nestedTypes.forEach(nestedTypeName => {
|
|
202
|
-
if (nestedTypesToCreate.indexOf(nestedTypeName) !== -1
|
|
223
|
+
if (nestedTypesToCreate.indexOf(nestedTypeName) !== -1 ||
|
|
224
|
+
(definitions[nestedTypeName] && definitions[nestedTypeName].isCrudType)) {
|
|
203
225
|
return;
|
|
204
226
|
}
|
|
205
227
|
createSchema += `\n${definitions[nestedTypeName].schema}`;
|
package/dist/config/config.js
CHANGED
|
@@ -28,7 +28,6 @@ const useConfigDefaults = (config) => {
|
|
|
28
28
|
if (!config) {
|
|
29
29
|
config = (0, exports.getEnvConfig)();
|
|
30
30
|
}
|
|
31
|
-
console.log(config);
|
|
32
31
|
return {
|
|
33
32
|
serverAddress: config.serverAddress,
|
|
34
33
|
keepaliveTimeout: (_a = config.keepaliveTimeout) !== null && _a !== void 0 ? _a : 3 * 1000,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/crud",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"homepage": "https://github.com/fraym/crud-nodejs",
|
|
6
6
|
"repository": {
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
"clean": "rm -rf dist",
|
|
17
17
|
"prepublishOnly": "npm test && npm run lint && npm run build",
|
|
18
18
|
"preversion": "npm run lint",
|
|
19
|
-
"cmd": "dist/cmd/crud.js"
|
|
20
|
-
"cmd2": "dist/cmd/crud.js --config .tst/crud.config.json"
|
|
19
|
+
"cmd": "dist/cmd/crud.js"
|
|
21
20
|
},
|
|
22
21
|
"files": [
|
|
23
22
|
"dist/**/*"
|
|
@@ -33,7 +32,6 @@
|
|
|
33
32
|
"@graphql-tools/load": "^7.8.6",
|
|
34
33
|
"@grpc/grpc-js": "^1.7.2",
|
|
35
34
|
"dotenv": "^16.0.3",
|
|
36
|
-
"fs": "^0.0.1-security",
|
|
37
35
|
"graphql": "^16.6.0",
|
|
38
36
|
"yargs": "^17.6.2"
|
|
39
37
|
},
|