@fraym/crud 0.15.1 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/cmd/crud.js +13 -8
- package/dist/config/config.d.ts +9 -3
- package/dist/config/config.js +25 -6
- package/dist/delivery/client.d.ts +2 -2
- package/dist/delivery/client.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -3
- package/dist/management/client.d.ts +3 -5
- package/dist/management/client.js +7 -23
- package/dist/management/getAll.d.ts +2 -2
- package/dist/management/getAll.js +8 -9
- package/dist/management/remove.d.ts +2 -2
- package/dist/management/remove.js +9 -10
- package/dist/management/upsert.d.ts +2 -0
- package/dist/management/upsert.js +16 -0
- package/package.json +1 -1
- package/dist/management/create.d.ts +0 -2
- package/dist/management/create.js +0 -17
- package/dist/management/update.d.ts +0 -2
- package/dist/management/update.js +0 -17
package/README.md
CHANGED
|
@@ -20,7 +20,10 @@ You need to add the `Tenant-Id` header in order to use the graphQL Endpoint and
|
|
|
20
20
|
Use the `crud` cli command to automatically apply your crud schemas to the crud service.
|
|
21
21
|
|
|
22
22
|
Your type schemas have to match the glob you specify in the `CRUD_SCHEMA_GLOB` env variable (default: `./src/**/*.graphql`).
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
Delivery API: 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`).
|
|
25
|
+
|
|
26
|
+
Management API: You can specify the address (and port) of the crud service instance you use in the `CRUD_MANAGEMENT_SERVER_ADDRESS` env variable (default: `http://127.0.0.1`). You will also need to set the `CRUD_MANAGEMENT_API_TOKEN` variable. The value of that token has to match the token configured in the crud service.
|
|
24
27
|
|
|
25
28
|
You might have a seperate permissions directory or file. As soon as your permissions schema enum is not part of the projections glob you can specify a `PERMISSIONS_SCHEMA_GLOB` env variable. It is empty by default but as soon as you provide it it will add the files in that glob to your projections schema, too.
|
|
26
29
|
|
|
@@ -34,6 +37,8 @@ Use a `.env` file or env variables to configure cte clients and the command:
|
|
|
34
37
|
|
|
35
38
|
```env
|
|
36
39
|
CRUD_SERVER_ADDRESS=127.0.0.1:9000
|
|
40
|
+
CRUD_MANAGEMENT_SERVER_ADDRESS=http://127.0.0.1
|
|
41
|
+
CRUD_MANAGEMENT_API_TOKEN=
|
|
37
42
|
CRUD_SCHEMA_GLOB=./src/crud/*.graphql
|
|
38
43
|
PERMISSIONS_SCHEMA_GLOB=
|
|
39
44
|
CRUD_NAMESPACE=
|
package/dist/cmd/crud.js
CHANGED
|
@@ -17,13 +17,15 @@ const run = async () => {
|
|
|
17
17
|
.config({
|
|
18
18
|
schemaGlob: "./src/**/*.graphql",
|
|
19
19
|
permissionsSchemaGlob: "",
|
|
20
|
-
serverAddress: "127.0.0.1
|
|
20
|
+
serverAddress: "http://127.0.0.1",
|
|
21
|
+
apiToken: "",
|
|
21
22
|
namespace: "",
|
|
22
23
|
})
|
|
23
24
|
.pkgConf("crud").argv;
|
|
24
25
|
let schemaGlob = argv.schemaGlob;
|
|
25
26
|
let permissionsSchemaGlob = argv.permissionsSchemaGlob;
|
|
26
27
|
let serverAddress = argv.serverAddress;
|
|
28
|
+
let apiToken = argv.apiToken;
|
|
27
29
|
let namespace = argv.namespace;
|
|
28
30
|
if (process.env.CRUD_SCHEMA_GLOB) {
|
|
29
31
|
schemaGlob = process.env.CRUD_SCHEMA_GLOB;
|
|
@@ -31,8 +33,11 @@ const run = async () => {
|
|
|
31
33
|
if (process.env.PERMISSIONS_SCHEMA_GLOB) {
|
|
32
34
|
permissionsSchemaGlob = process.env.PERMISSIONS_SCHEMA_GLOB;
|
|
33
35
|
}
|
|
34
|
-
if (process.env.
|
|
35
|
-
serverAddress = process.env.
|
|
36
|
+
if (process.env.CRUD_MANAGEMENT_SERVER_ADDRESS) {
|
|
37
|
+
serverAddress = process.env.CRUD_MANAGEMENT_SERVER_ADDRESS;
|
|
38
|
+
}
|
|
39
|
+
if (process.env.CRUD_MANAGEMENT_API_TOKEN) {
|
|
40
|
+
apiToken = process.env.CRUD_MANAGEMENT_API_TOKEN;
|
|
36
41
|
}
|
|
37
42
|
if (process.env.CRUD_NAMESPACE) {
|
|
38
43
|
namespace = process.env.CRUD_NAMESPACE;
|
|
@@ -48,7 +53,7 @@ const run = async () => {
|
|
|
48
53
|
loaders: [new graphql_file_loader_1.GraphQLFileLoader()],
|
|
49
54
|
});
|
|
50
55
|
const definitions = getTypeDefinition(schema, namespace);
|
|
51
|
-
await migrateSchemas(definitions, serverAddress, namespace);
|
|
56
|
+
await migrateSchemas(definitions, serverAddress, apiToken, namespace);
|
|
52
57
|
};
|
|
53
58
|
run();
|
|
54
59
|
const getTypeDefinition = (schema, namespace) => {
|
|
@@ -240,11 +245,11 @@ const addNestedTypesToSchema = (definitions, nestedTypeName, nestedTypes) => {
|
|
|
240
245
|
nestedTypes: nestedTypes,
|
|
241
246
|
};
|
|
242
247
|
};
|
|
243
|
-
const migrateSchemas = async (definitions, serverAddress, namespace) => {
|
|
248
|
+
const migrateSchemas = async (definitions, serverAddress, apiToken, namespace) => {
|
|
244
249
|
console.log(`Considering ${Object.keys(definitions).length} type definitions for migration.`);
|
|
245
250
|
console.log(`Using server address ${serverAddress}`);
|
|
246
251
|
console.log(`Using namespace ${namespace}`);
|
|
247
|
-
const managementClient = await (0, client_1.newManagementClient)({ serverAddress });
|
|
252
|
+
const managementClient = await (0, client_1.newManagementClient)({ serverAddress, apiToken });
|
|
248
253
|
const existingTypeNames = (await managementClient.getAllTypes()).filter(name => name.startsWith(namespace) && !name.startsWith("Fraym"));
|
|
249
254
|
let createSchema = "";
|
|
250
255
|
let updateSchema = "";
|
|
@@ -295,12 +300,12 @@ const migrateSchemas = async (definitions, serverAddress, namespace) => {
|
|
|
295
300
|
});
|
|
296
301
|
if (typesToCreate.length > 0) {
|
|
297
302
|
console.log(`Creating ${typesToCreate.length} types: ${typesToCreate}...`);
|
|
298
|
-
await managementClient.
|
|
303
|
+
await managementClient.upsertTypes(createSchema);
|
|
299
304
|
console.log(`Created ${typesToCreate.length} types`);
|
|
300
305
|
}
|
|
301
306
|
if (typesToUpdate.length > 0) {
|
|
302
307
|
console.log(`Updating ${typesToUpdate.length} types: ${typesToUpdate}...`);
|
|
303
|
-
await managementClient.
|
|
308
|
+
await managementClient.upsertTypes(updateSchema);
|
|
304
309
|
console.log(`Updated ${typesToUpdate.length} types`);
|
|
305
310
|
}
|
|
306
311
|
if (typesToRemove.length > 0) {
|
package/dist/config/config.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface DeliveryClientConfig {
|
|
2
2
|
serverAddress: string;
|
|
3
3
|
keepaliveInterval?: number;
|
|
4
4
|
keepaliveTimeout?: number;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export interface ManagementClientConfig {
|
|
7
|
+
serverAddress: string;
|
|
8
|
+
apiToken: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const getEnvDeliveryConfig: () => DeliveryClientConfig;
|
|
11
|
+
export declare const getEnvManagementConfig: () => ManagementClientConfig;
|
|
12
|
+
export declare const useDeliveryConfigDefaults: (config?: DeliveryClientConfig) => Required<DeliveryClientConfig>;
|
|
13
|
+
export declare const useManagementConfigDefaults: (config?: ManagementClientConfig) => Required<ManagementClientConfig>;
|
package/dist/config/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.useManagementConfigDefaults = exports.useDeliveryConfigDefaults = exports.getEnvManagementConfig = exports.getEnvDeliveryConfig = void 0;
|
|
4
4
|
const dotenv_1 = require("dotenv");
|
|
5
|
-
const
|
|
5
|
+
const getEnvDeliveryConfig = () => {
|
|
6
6
|
var _a;
|
|
7
7
|
(0, dotenv_1.config)();
|
|
8
8
|
const serverAddress = (_a = process.env.CRUD_SERVER_ADDRESS) !== null && _a !== void 0 ? _a : "";
|
|
@@ -22,11 +22,20 @@ const getEnvConfig = () => {
|
|
|
22
22
|
keepaliveTimeout,
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
exports.
|
|
26
|
-
const
|
|
25
|
+
exports.getEnvDeliveryConfig = getEnvDeliveryConfig;
|
|
26
|
+
const getEnvManagementConfig = () => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
(0, dotenv_1.config)();
|
|
29
|
+
return {
|
|
30
|
+
serverAddress: (_a = process.env.CRUD_MANAGEMENT_SERVER_ADDRESS) !== null && _a !== void 0 ? _a : "",
|
|
31
|
+
apiToken: (_b = process.env.CRUD_MANAGEMENT_API_TOKEN) !== null && _b !== void 0 ? _b : "",
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.getEnvManagementConfig = getEnvManagementConfig;
|
|
35
|
+
const useDeliveryConfigDefaults = (config) => {
|
|
27
36
|
var _a, _b;
|
|
28
37
|
if (!config) {
|
|
29
|
-
config = (0, exports.
|
|
38
|
+
config = (0, exports.getEnvDeliveryConfig)();
|
|
30
39
|
}
|
|
31
40
|
return {
|
|
32
41
|
serverAddress: config.serverAddress,
|
|
@@ -34,4 +43,14 @@ const useConfigDefaults = (config) => {
|
|
|
34
43
|
keepaliveInterval: (_b = config.keepaliveInterval) !== null && _b !== void 0 ? _b : 40 * 1000,
|
|
35
44
|
};
|
|
36
45
|
};
|
|
37
|
-
exports.
|
|
46
|
+
exports.useDeliveryConfigDefaults = useDeliveryConfigDefaults;
|
|
47
|
+
const useManagementConfigDefaults = (config) => {
|
|
48
|
+
if (!config) {
|
|
49
|
+
config = (0, exports.getEnvManagementConfig)();
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
serverAddress: config.serverAddress,
|
|
53
|
+
apiToken: config.apiToken,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.useManagementConfigDefaults = useManagementConfigDefaults;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeliveryClientConfig } from "../config/config";
|
|
2
2
|
import { CreatedCrudData } from "./create";
|
|
3
3
|
import { GetCrudDataList } from "./getDataList";
|
|
4
4
|
import { Filter } from "./filter";
|
|
@@ -11,4 +11,4 @@ export interface DeliveryClient {
|
|
|
11
11
|
getDataList: <T extends {}>(tenantId: string, type: string, limit?: number, page?: number, filter?: Filter, order?: Order[]) => Promise<GetCrudDataList<T>>;
|
|
12
12
|
close: () => Promise<void>;
|
|
13
13
|
}
|
|
14
|
-
export declare const newDeliveryClient: (config?:
|
|
14
|
+
export declare const newDeliveryClient: (config?: DeliveryClientConfig) => Promise<DeliveryClient>;
|
package/dist/delivery/client.js
CHANGED
|
@@ -10,7 +10,7 @@ const delete_1 = require("./delete");
|
|
|
10
10
|
const getData_1 = require("./getData");
|
|
11
11
|
const getDataList_1 = require("./getDataList");
|
|
12
12
|
const newDeliveryClient = async (config) => {
|
|
13
|
-
config = (0, config_1.
|
|
13
|
+
config = (0, config_1.useDeliveryConfigDefaults)(config);
|
|
14
14
|
const serviceClient = new crud_proto_1.DeliveryServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
|
|
15
15
|
"grpc.keepalive_time_ms": config.keepaliveInterval,
|
|
16
16
|
"grpc.keepalive_timeout_ms": config.keepaliveTimeout,
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export * from "./delivery/client";
|
|
|
2
2
|
export * from "./management/client";
|
|
3
3
|
export { Filter, FieldFilter } from "./delivery/filter";
|
|
4
4
|
export { Order } from "./delivery/order";
|
|
5
|
-
export
|
|
5
|
+
export * from "./config/config";
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getEnvConfig = void 0;
|
|
18
17
|
__exportStar(require("./delivery/client"), exports);
|
|
19
18
|
__exportStar(require("./management/client"), exports);
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, "getEnvConfig", { enumerable: true, get: function () { return config_1.getEnvConfig; } });
|
|
19
|
+
__exportStar(require("./config/config"), exports);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ManagementClientConfig } from "../config/config";
|
|
2
2
|
export interface ManagementClient {
|
|
3
|
-
|
|
4
|
-
updateTypes: (schema: string) => Promise<void>;
|
|
3
|
+
upsertTypes: (schema: string) => Promise<void>;
|
|
5
4
|
removeTypes: (typeNames: string[]) => Promise<void>;
|
|
6
5
|
getAllTypes: () => Promise<string[]>;
|
|
7
|
-
close: () => Promise<void>;
|
|
8
6
|
}
|
|
9
|
-
export declare const newManagementClient: (config?:
|
|
7
|
+
export declare const newManagementClient: (config?: ManagementClientConfig) => Promise<ManagementClient>;
|
|
@@ -1,41 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.newManagementClient = void 0;
|
|
4
|
-
const crud_proto_1 = require("@fraym/crud-proto");
|
|
5
|
-
const grpc_js_1 = require("@grpc/grpc-js");
|
|
6
4
|
const config_1 = require("../config/config");
|
|
7
|
-
const create_1 = require("./create");
|
|
8
5
|
const getAll_1 = require("./getAll");
|
|
9
6
|
const remove_1 = require("./remove");
|
|
10
|
-
const
|
|
7
|
+
const upsert_1 = require("./upsert");
|
|
11
8
|
const newManagementClient = async (config) => {
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
"grpc.keepalive_timeout_ms": config.keepaliveTimeout,
|
|
16
|
-
"grpc.keepalive_permit_without_calls": 1,
|
|
17
|
-
});
|
|
18
|
-
const createTypes = async (schema) => {
|
|
19
|
-
await (0, create_1.createCrudTypes)(schema, serviceClient);
|
|
20
|
-
};
|
|
21
|
-
const updateTypes = async (schema) => {
|
|
22
|
-
await (0, update_1.updateCrudTypes)(schema, serviceClient);
|
|
9
|
+
const currentConfig = (0, config_1.useManagementConfigDefaults)(config);
|
|
10
|
+
const upsertTypes = async (schema) => {
|
|
11
|
+
await (0, upsert_1.upsertCrudTypes)(schema, currentConfig);
|
|
23
12
|
};
|
|
24
13
|
const removeTypes = async (typeNames) => {
|
|
25
|
-
await (0, remove_1.removeCrudTypes)(typeNames,
|
|
14
|
+
await (0, remove_1.removeCrudTypes)(typeNames, currentConfig);
|
|
26
15
|
};
|
|
27
16
|
const getAllTypes = async () => {
|
|
28
|
-
return await (0, getAll_1.getAllCrudTypes)(
|
|
29
|
-
};
|
|
30
|
-
const close = async () => {
|
|
31
|
-
serviceClient.close();
|
|
17
|
+
return await (0, getAll_1.getAllCrudTypes)(currentConfig);
|
|
32
18
|
};
|
|
33
19
|
return {
|
|
34
|
-
|
|
35
|
-
updateTypes,
|
|
20
|
+
upsertTypes,
|
|
36
21
|
removeTypes,
|
|
37
22
|
getAllTypes,
|
|
38
|
-
close,
|
|
39
23
|
};
|
|
40
24
|
};
|
|
41
25
|
exports.newManagementClient = newManagementClient;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const getAllCrudTypes: (
|
|
1
|
+
import { ManagementClientConfig } from "config/config";
|
|
2
|
+
export declare const getAllCrudTypes: (config: ManagementClientConfig) => Promise<string[]>;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAllCrudTypes = void 0;
|
|
4
|
-
const getAllCrudTypes = async (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
resolve(response.typeNames);
|
|
12
|
-
});
|
|
4
|
+
const getAllCrudTypes = async (config) => {
|
|
5
|
+
const response = await fetch(`${config.serverAddress}/management/types`, {
|
|
6
|
+
method: "GET",
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${config.apiToken}`,
|
|
9
|
+
},
|
|
13
10
|
});
|
|
11
|
+
const data = await response.json();
|
|
12
|
+
return data.typeNames;
|
|
14
13
|
};
|
|
15
14
|
exports.getAllCrudTypes = getAllCrudTypes;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const removeCrudTypes: (typeNames: string[],
|
|
1
|
+
import { ManagementClientConfig } from "config/config";
|
|
2
|
+
export declare const removeCrudTypes: (typeNames: string[], config: ManagementClientConfig) => Promise<void>;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeCrudTypes = void 0;
|
|
4
|
-
const removeCrudTypes = async (typeNames,
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const removeCrudTypes = async (typeNames, config) => {
|
|
5
|
+
await fetch(`${config.serverAddress}/management/types`, {
|
|
6
|
+
method: "DELETE",
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${config.apiToken}`,
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({
|
|
7
12
|
typeNames,
|
|
8
|
-
},
|
|
9
|
-
if (error) {
|
|
10
|
-
reject(error.message);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
resolve();
|
|
14
|
-
});
|
|
13
|
+
}),
|
|
15
14
|
});
|
|
16
15
|
};
|
|
17
16
|
exports.removeCrudTypes = removeCrudTypes;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upsertCrudTypes = void 0;
|
|
4
|
+
const upsertCrudTypes = async (schema, config) => {
|
|
5
|
+
await fetch(`${config.serverAddress}/management/types`, {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${config.apiToken}`,
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
schema,
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.upsertCrudTypes = upsertCrudTypes;
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCrudTypes = void 0;
|
|
4
|
-
const createCrudTypes = async (schema, serviceClient) => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
serviceClient.createTypes({
|
|
7
|
-
schema,
|
|
8
|
-
}, error => {
|
|
9
|
-
if (error) {
|
|
10
|
-
reject(error.message);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
resolve();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
exports.createCrudTypes = createCrudTypes;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateCrudTypes = void 0;
|
|
4
|
-
const updateCrudTypes = async (schema, serviceClient) => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
serviceClient.updateTypes({
|
|
7
|
-
schema,
|
|
8
|
-
}, error => {
|
|
9
|
-
if (error) {
|
|
10
|
-
reject(error.message);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
resolve();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
exports.updateCrudTypes = updateCrudTypes;
|