@fraym/projections 0.10.1 → 0.12.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 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 `projections` cli command to automatically apply your projection schemas to the projections service.
21
21
 
22
22
  Your type schemas have to match the glob you specify in the `PROJECTIONS_SCHEMA_GLOB` env variable (default: `./src/**/*.graphql`).
23
- You can specify the address (and port) of the projections service instance you use in the `PROJECTIONS_SERVER_ADDRESS` env variable (default: `127.0.0.1:9000`).
23
+
24
+ Delivery API: You can specify the address (and port) of the projections service instance you use in the `PROJECTIONS_SERVER_ADDRESS` env variable (default: `127.0.0.1:9000`).
25
+
26
+ Management API: You can specify the address (and port) of the projections service instance you use in the `PROJECTIONS_MANAGEMENT_SERVER_ADDRESS` env variable (default: `http://127.0.0.1`). You will also need to set the `PROJECTIONS_MANAGEMENT_API_TOKEN` variable. The value of that token has to match the token configured in the projections 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
  PROJECTIONS_SERVER_ADDRESS=127.0.0.1:9000
40
+ PROJECTIONS_MANAGEMENT_SERVER_ADDRESS=http://127.0.0.1
41
+ PROJECTIONS_MANAGEMENT_API_TOKEN=
37
42
  PROJECTIONS_SCHEMA_GLOB=./src/projections/*.graphql
38
43
  PERMISSIONS_SCHEMA_GLOB=
39
44
  PROJECTIONS_NAMESPACE=
@@ -85,19 +90,90 @@ await managementClient.remove(["YourProjection"]);
85
90
  const list = await managementClient.getAll();
86
91
  ```
87
92
 
88
- ### Get a single projection element
93
+ ### Authorization
89
94
 
90
- The name of `YourProjection` has to equal your projection name in your schema (also in casing).
91
- The `id` has to match the id of the projection element that you want to get.
95
+ All delivery client functions make use of the `AuthData` object.
96
+ This data is used to check access for the desired action.
97
+
98
+ You can add the `FRAYM_AUTH_OWNER` scope in case you are performing an action that is no subject to restrictions.
99
+
100
+ Fields:
101
+
102
+ - `tenantId`: Id of the tenant to use
103
+ - `scopes`: Slice of scopes to use for the action
104
+ - `data`: Data that is used in directives like `@filterFromJwtData`
105
+
106
+ ### Upsert data in projection
107
+
108
+ In general you upsert data by publishing events on the event stream.
109
+ There are cases where you want to improve performance and get detailed validation output. In these cases you can use the client to directly upsert data. Do not worry, this is still event based under the hood.
92
110
 
93
111
  ```typescript
94
- const data = await deliveryClient.getData("tenantId", "YourProjection", "id");
112
+ const response = await client.upsertData<{ fieldName: string }>(
113
+ "ProjectionName",
114
+ authData,
115
+ "dataId",
116
+ {
117
+ fieldName: "value",
118
+ }
119
+ );
120
+ ```
121
+
122
+ The response contains the following fields:
123
+
124
+ In case of no validation errors:
125
+
126
+ - `data`: The new data after your upsert action
127
+
128
+ In case of validation errors:
129
+
130
+ - `validationErrors`: List of global validation errors that are not related to a single field
131
+ - `fieldValidationErrors`: Validation errors mapped by the name of the field that they relate to
132
+
133
+ ### Delete data from projection
134
+
135
+ In general you delete data by publishing events on the event stream.
136
+ There are cases where you want to improve performance and get detailed validation output. In these cases you can use the client to directly delete data. Do not worry, this is still event based under the hood.
137
+
138
+ Delete by Id:
139
+
140
+ ```go
141
+ const numberOfDeletedEntries = await client.deleteDataById("ProjectionName", authData, "dataId")
142
+ ```
143
+
144
+ Delete by filter:
145
+
146
+ ```go
147
+ const numberOfDeletedEntries = client.deleteDataByFilter("ProjectionName", authData, filter)
148
+ ```
149
+
150
+ ### Get a single projection element
151
+
152
+ A filter could look like this:
153
+
154
+ ```go
155
+ const filter := {
156
+ fields: {
157
+ fieldName: {
158
+ operation: "equals",
159
+ type: "Int",
160
+ value: 123,
161
+ },
162
+ },
163
+ }
95
164
  ```
96
165
 
97
- You can specify a fourth parameter if you want to return a empty dataset instead of getting an error when querying a non existing element:
166
+ The name of `YourProjection` has to equal your projection name in your schema (also in casing).
167
+ The `id` has to match the id of the projection element that you want to get.
98
168
 
99
169
  ```typescript
100
- const data = await deliveryClient.getData("tenantId", "YourProjection", "id", true);
170
+ const data = await deliveryClient.getData(
171
+ "YourProjection",
172
+ authData,
173
+ "id",
174
+ filter,
175
+ returnEmptyDataIfNotFound
176
+ );
101
177
  ```
102
178
 
103
179
  ### Get (paginated / filtered) data
@@ -107,29 +183,42 @@ The name of `YourProjection` has to equal your type name in your schema (also in
107
183
  No pagination:
108
184
 
109
185
  ```typescript
110
- const data = await deliveryClient.getDataList("tenantId", "YourProjection");
186
+ const dataList = await deliveryClient.getDataList("YourProjection", authData);
111
187
  ```
112
188
 
189
+ The dataList response contains the following fields:
190
+
191
+ - `limit`: The pagination limit
192
+ - `page`: The pagination page
193
+ - `total`: The total amount of elements matching the given filter
194
+ - `data`: The selected data
195
+
113
196
  With pagination:
114
197
 
115
198
  ```typescript
116
199
  const limit = 50; // elements to query per page
117
200
  const page = 1; // number of the page you want to select, first page starts at: 1
118
- const data = await deliveryClient.getDataList("tenantId", "YourProjection", limit, page);
201
+ const dataList = await deliveryClient.getDataList("YourProjection", authData, limit, page);
119
202
  ```
120
203
 
121
204
  With filter:
122
205
 
123
206
  ```typescript
124
- const data = await deliveryClient.getDataList("tenantId", "YourProjection", undefined, undefined, {
125
- fields: {
126
- fieldName: {
127
- operation: "equals",
128
- type: "Int",
129
- value: 123,
207
+ const dataList = await deliveryClient.getDataList(
208
+ "YourProjection",
209
+ authData,
210
+ undefined,
211
+ undefined,
212
+ {
213
+ fields: {
214
+ fieldName: {
215
+ operation: "equals",
216
+ type: "Int",
217
+ value: 123,
218
+ },
130
219
  },
131
- },
132
- });
220
+ }
221
+ );
133
222
  ```
134
223
 
135
224
  All `Filter`s are evaluated by:
@@ -176,9 +265,9 @@ With order:
176
265
  All order definitions are prioritized in the order that they are defined (the first definition is prioritized over the second).
177
266
 
178
267
  ```typescript
179
- const data = await client.getDataList(
180
- "tenantId",
268
+ const dataList = await client.getDataList(
181
269
  "YourProjection",
270
+ authData,
182
271
  undefined,
183
272
  undefined,
184
273
  undefined,
@@ -191,7 +280,7 @@ const data = await client.getDataList(
191
280
  );
192
281
  ```
193
282
 
194
- ### Gracefully close the clients
283
+ ### Gracefully close the delivery client
195
284
 
196
285
  You won't lose any data if you don't. Use it for your peace of mind.
197
286
 
@@ -18,12 +18,14 @@ const run = async () => {
18
18
  schemaGlob: "./src/**/*.graphql",
19
19
  permissionsSchemaGlob: "",
20
20
  serverAddress: "127.0.0.1:9000",
21
+ apiToken: "",
21
22
  namespace: "",
22
23
  })
23
24
  .pkgConf("projections").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.PROJECTIONS_SCHEMA_GLOB) {
29
31
  schemaGlob = process.env.PROJECTIONS_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.PROJECTIONS_SERVER_ADDRESS) {
35
- serverAddress = process.env.PROJECTIONS_SERVER_ADDRESS;
36
+ if (process.env.PROJECTIONS_MANAGEMENT_SERVER_ADDRESS) {
37
+ serverAddress = process.env.PROJECTIONS_MANAGEMENT_SERVER_ADDRESS;
38
+ }
39
+ if (process.env.PROJECTIONS_MANAGEMENT_API_TOKEN) {
40
+ apiToken = process.env.PROJECTIONS_MANAGEMENT_API_TOKEN;
36
41
  }
37
42
  if (process.env.PROJECTIONS_NAMESPACE) {
38
43
  namespace = process.env.PROJECTIONS_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) => {
@@ -243,8 +248,8 @@ const addNestedTypesToSchema = (definitions, nestedTypeName, nestedTypes) => {
243
248
  nestedTypes: nestedTypes,
244
249
  };
245
250
  };
246
- const migrateSchemas = async (definitions, serverAddress, namespace) => {
247
- const managementClient = await (0, client_1.newManagementClient)({ serverAddress });
251
+ const migrateSchemas = async (definitions, serverAddress, apiToken, namespace) => {
252
+ const managementClient = await (0, client_1.newManagementClient)({ serverAddress, apiToken });
248
253
  let existingProjections = (await managementClient.getAll()).filter(projectionName => !projectionName.startsWith("Crud") &&
249
254
  !projectionName.startsWith("Fraym") &&
250
255
  projectionName.startsWith(namespace));
@@ -297,12 +302,12 @@ const migrateSchemas = async (definitions, serverAddress, namespace) => {
297
302
  });
298
303
  if (projectionsToCreate.length > 0) {
299
304
  console.log(`Creating ${projectionsToCreate.length} projections: ${projectionsToCreate}...`);
300
- await managementClient.update(createSchema);
305
+ await managementClient.upsert(createSchema);
301
306
  console.log(`Created ${projectionsToCreate.length} projections`);
302
307
  }
303
308
  if (projectionsToUpdate.length > 0) {
304
309
  console.log(`Updating ${projectionsToUpdate.length} projections: ${projectionsToUpdate}...`);
305
- await managementClient.update(updateSchema);
310
+ await managementClient.upsert(updateSchema);
306
311
  console.log(`Updated ${projectionsToUpdate.length} projections`);
307
312
  }
308
313
  if (projectionsToRemove.length > 0) {
@@ -1,7 +1,13 @@
1
- export interface ClientConfig {
1
+ export interface DeliveryClientConfig {
2
2
  serverAddress: string;
3
3
  keepaliveInterval?: number;
4
4
  keepaliveTimeout?: number;
5
5
  }
6
- export declare const getEnvConfig: () => ClientConfig;
7
- export declare const useConfigDefaults: (config?: ClientConfig) => Required<ClientConfig>;
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>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useConfigDefaults = exports.getEnvConfig = void 0;
3
+ exports.useManagementConfigDefaults = exports.useDeliveryConfigDefaults = exports.getEnvManagementConfig = exports.getEnvDeliveryConfig = void 0;
4
4
  const dotenv_1 = require("dotenv");
5
- const getEnvConfig = () => {
5
+ const getEnvDeliveryConfig = () => {
6
6
  var _a;
7
7
  (0, dotenv_1.config)();
8
8
  const serverAddress = (_a = process.env.PROJECTIONS_SERVER_ADDRESS) !== null && _a !== void 0 ? _a : "";
@@ -22,11 +22,20 @@ const getEnvConfig = () => {
22
22
  keepaliveTimeout,
23
23
  };
24
24
  };
25
- exports.getEnvConfig = getEnvConfig;
26
- const useConfigDefaults = (config) => {
25
+ exports.getEnvDeliveryConfig = getEnvDeliveryConfig;
26
+ const getEnvManagementConfig = () => {
27
+ var _a, _b;
28
+ (0, dotenv_1.config)();
29
+ return {
30
+ serverAddress: (_a = process.env.PROJECTIONS_MANAGEMENT_SERVER_ADDRESS) !== null && _a !== void 0 ? _a : "",
31
+ apiToken: (_b = process.env.PROJECTIONS_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.getEnvConfig)();
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.useConfigDefaults = useConfigDefaults;
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 { ClientConfig } from "../config/config";
1
+ import { DeliveryClientConfig } from "../config/config";
2
2
  import { Filter } from "./filter";
3
3
  import { GetProjectionDataList } from "./getDataList";
4
4
  import { Order } from "./order";
@@ -12,4 +12,4 @@ export interface DeliveryClient {
12
12
  deleteDataByFilter: (projection: string, authData: AuthData, filter?: Filter) => Promise<number>;
13
13
  close: () => Promise<void>;
14
14
  }
15
- export declare const newDeliveryClient: (config?: ClientConfig) => Promise<DeliveryClient>;
15
+ export declare const newDeliveryClient: (config?: DeliveryClientConfig) => Promise<DeliveryClient>;
@@ -9,7 +9,7 @@ const getDataList_1 = require("./getDataList");
9
9
  const upsert_1 = require("./upsert");
10
10
  const delete_1 = require("./delete");
11
11
  const newDeliveryClient = async (config) => {
12
- config = (0, config_1.useConfigDefaults)(config);
12
+ config = (0, config_1.useDeliveryConfigDefaults)(config);
13
13
  const serviceClient = new projections_proto_1.DeliveryServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
14
14
  "grpc.keepalive_time_ms": config.keepaliveInterval,
15
15
  "grpc.keepalive_timeout_ms": config.keepaliveTimeout,
@@ -5,6 +5,7 @@ import { Order } from "./order";
5
5
  export interface GetProjectionDataList<T extends {}> {
6
6
  limit: number;
7
7
  page: number;
8
+ total: number;
8
9
  data: T[];
9
10
  }
10
11
  export declare const getProjectionDataList: <T extends {}>(projection: string, auth: AuthData, limit: number, page: number, filter: Filter, order: Order[], serviceClient: DeliveryServiceClient) => Promise<GetProjectionDataList<T> | null>;
@@ -30,6 +30,7 @@ const getProjectionDataList = async (projection, auth, limit, page, filter, orde
30
30
  resolve({
31
31
  limit: response.limit,
32
32
  page: response.page,
33
+ total: response.total,
33
34
  data,
34
35
  });
35
36
  });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ClientConfig, getEnvConfig } from "./config/config";
1
+ export * from "./config/config";
2
2
  export * from "./management/client";
3
3
  export * from "./delivery/client";
4
4
  export { Filter, FieldFilter } from "./delivery/filter";
package/dist/index.js CHANGED
@@ -14,9 +14,8 @@ 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.isUpsertValidationResponse = exports.isUpsertSuccessResponse = exports.getEnvConfig = void 0;
18
- var config_1 = require("./config/config");
19
- Object.defineProperty(exports, "getEnvConfig", { enumerable: true, get: function () { return config_1.getEnvConfig; } });
17
+ exports.isUpsertValidationResponse = exports.isUpsertSuccessResponse = void 0;
18
+ __exportStar(require("./config/config"), exports);
20
19
  __exportStar(require("./management/client"), exports);
21
20
  __exportStar(require("./delivery/client"), exports);
22
21
  var upsert_1 = require("./delivery/upsert");
@@ -1,9 +1,7 @@
1
- import { ClientConfig } from "../config/config";
1
+ import { ManagementClientConfig } from "../config/config";
2
2
  export interface ManagementClient {
3
- create: (schema: string) => Promise<void>;
4
- update: (schema: string) => Promise<void>;
3
+ upsert: (schema: string) => Promise<void>;
5
4
  remove: (projectionNames: string[]) => Promise<void>;
6
5
  getAll: () => Promise<string[]>;
7
- close: () => Promise<void>;
8
6
  }
9
- export declare const newManagementClient: (config?: ClientConfig) => Promise<ManagementClient>;
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 projections_proto_1 = require("@fraym/projections-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 update_1 = require("./update");
7
+ const upsert_1 = require("./upsert");
11
8
  const newManagementClient = async (config) => {
12
- config = (0, config_1.useConfigDefaults)(config);
13
- const serviceClient = new projections_proto_1.ManagementServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
14
- "grpc.keepalive_time_ms": config.keepaliveInterval,
15
- "grpc.keepalive_timeout_ms": config.keepaliveTimeout,
16
- "grpc.keepalive_permit_without_calls": 1,
17
- });
18
- const create = async (schema) => {
19
- await (0, create_1.createProjections)(schema, serviceClient);
20
- };
21
- const update = async (schema) => {
22
- await (0, update_1.updateProjections)(schema, serviceClient);
9
+ const currentConfig = (0, config_1.useManagementConfigDefaults)(config);
10
+ const upsert = async (schema) => {
11
+ await (0, upsert_1.upsertProjections)(schema, currentConfig);
23
12
  };
24
13
  const remove = async (projectionNames) => {
25
- await (0, remove_1.removeProjections)(projectionNames, serviceClient);
14
+ await (0, remove_1.removeProjections)(projectionNames, currentConfig);
26
15
  };
27
16
  const getAll = async () => {
28
- return await (0, getAll_1.getAllProjections)(serviceClient);
29
- };
30
- const close = async () => {
31
- serviceClient.close();
17
+ return await (0, getAll_1.getAllProjections)(currentConfig);
32
18
  };
33
19
  return {
34
- create,
35
- update,
20
+ upsert,
36
21
  remove,
37
22
  getAll,
38
- close,
39
23
  };
40
24
  };
41
25
  exports.newManagementClient = newManagementClient;
@@ -1,2 +1,2 @@
1
- import { ManagementServiceClient } from "@fraym/projections-proto";
2
- export declare const getAllProjections: (serviceClient: ManagementServiceClient) => Promise<string[]>;
1
+ import { ManagementClientConfig } from "config/config";
2
+ export declare const getAllProjections: (config: ManagementClientConfig) => Promise<string[]>;
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAllProjections = void 0;
4
- const getAllProjections = async (serviceClient) => {
5
- return new Promise((resolve, reject) => {
6
- serviceClient.getProjections({}, (error, response) => {
7
- if (error) {
8
- reject(error.message);
9
- return;
10
- }
11
- resolve(response.projectionNames);
12
- });
4
+ const getAllProjections = async (config) => {
5
+ const response = await fetch(`${config.serverAddress}/management/projections`, {
6
+ method: "GET",
7
+ headers: {
8
+ Authorization: `Bearer ${config.apiToken}`,
9
+ },
13
10
  });
11
+ const data = await response.json();
12
+ return data.projectionNames;
14
13
  };
15
14
  exports.getAllProjections = getAllProjections;
@@ -1,2 +1,2 @@
1
- import { ManagementServiceClient } from "@fraym/projections-proto";
2
- export declare const removeProjections: (projectionNames: string[], serviceClient: ManagementServiceClient) => Promise<void>;
1
+ import { ManagementClientConfig } from "config/config";
2
+ export declare const removeProjections: (projectionNames: string[], config: ManagementClientConfig) => Promise<void>;
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeProjections = void 0;
4
- const removeProjections = async (projectionNames, serviceClient) => {
5
- return new Promise((resolve, reject) => {
6
- serviceClient.removeProjections({
4
+ const removeProjections = async (projectionNames, config) => {
5
+ await fetch(`${config.serverAddress}/management/projections`, {
6
+ method: "DELETE",
7
+ headers: {
8
+ Authorization: `Bearer ${config.apiToken}`,
9
+ "Content-Type": "application/json",
10
+ },
11
+ body: JSON.stringify({
7
12
  projectionNames,
8
- }, error => {
9
- if (error) {
10
- reject(error.message);
11
- return;
12
- }
13
- resolve();
14
- });
13
+ }),
15
14
  });
16
15
  };
17
16
  exports.removeProjections = removeProjections;
@@ -0,0 +1,2 @@
1
+ import { ManagementClientConfig } from "config/config";
2
+ export declare const upsertProjections: (schema: string, config: ManagementClientConfig) => Promise<void>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upsertProjections = void 0;
4
+ const upsertProjections = async (schema, config) => {
5
+ await fetch(`${config.serverAddress}/management/projections`, {
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.upsertProjections = upsertProjections;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/projections",
3
- "version": "0.10.1",
3
+ "version": "0.12.0",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/projections-nodejs",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "projections": "dist/cmd/projections.js"
28
28
  },
29
29
  "dependencies": {
30
- "@fraym/projections-proto": "^1.0.0-alpha.14",
30
+ "@fraym/projections-proto": "^1.0.0-alpha.15",
31
31
  "@graphql-tools/graphql-file-loader": "^7.5.16",
32
32
  "@graphql-tools/load": "^7.8.13",
33
33
  "@grpc/grpc-js": "^1.8.12",
@@ -1,2 +0,0 @@
1
- import { ManagementServiceClient } from "@fraym/projections-proto";
2
- export declare const createProjections: (schema: string, serviceClient: ManagementServiceClient) => Promise<void>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createProjections = void 0;
4
- const createProjections = async (schema, serviceClient) => {
5
- return new Promise((resolve, reject) => {
6
- serviceClient.createProjections({
7
- schema,
8
- }, error => {
9
- if (error) {
10
- reject(error.message);
11
- return;
12
- }
13
- resolve();
14
- });
15
- });
16
- };
17
- exports.createProjections = createProjections;
@@ -1,2 +0,0 @@
1
- import { ManagementServiceClient } from "@fraym/projections-proto";
2
- export declare const updateProjections: (schema: string, serviceClient: ManagementServiceClient) => Promise<void>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateProjections = void 0;
4
- const updateProjections = async (schema, serviceClient) => {
5
- return new Promise((resolve, reject) => {
6
- serviceClient.updateProjections({
7
- schema,
8
- }, error => {
9
- if (error) {
10
- reject(error.message);
11
- return;
12
- }
13
- resolve();
14
- });
15
- });
16
- };
17
- exports.updateProjections = updateProjections;