remult 0.20.3-exp.0 → 0.20.3-exp.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/esm/graphql.js CHANGED
@@ -89,6 +89,8 @@ export function remultGraphql(api) {
89
89
  root[key] = async (arg1, req, a) => {
90
90
  const { options, filter } = arg1;
91
91
  return new Promise(async (res, error) => {
92
+ if (req.req)
93
+ req = req.req; //TODO - yoga sends its own request object - and in it you get the original request (need to test with svelte and next)
92
94
  server.run(req, async () => {
93
95
  let dApi = await server.getDataApi(req, meta);
94
96
  let result;
@@ -416,37 +416,54 @@ export class RemultServerImplementation {
416
416
  let key = meta.key;
417
417
  let parameters = [];
418
418
  if (key) {
419
+ let mutationKey = key;
419
420
  let properties = {};
421
+ let mutationProperties = {};
420
422
  for (const f of meta.fields) {
421
423
  let type = f.valueType == String ? "string" :
422
424
  f.valueType == Boolean ? "boolean" :
423
425
  f.valueType == Date ? "string" :
424
426
  f.valueType == Number ? "number" :
425
427
  "object";
426
- properties[f.key] = {
427
- type
428
- };
429
- parameters.push({
430
- "name": f.key,
431
- "in": "query",
432
- "description": "filter equal to " + f.key,
433
- "required": false,
434
- "style": "simple",
435
- type
436
- });
437
- parameters.push({
438
- "name": f.key + "_ne",
439
- "in": "query",
440
- "description": "filter not equal to " + f.key,
441
- "required": false,
442
- "style": "simple",
443
- type
444
- });
428
+ if (f.options.includeInApi !== false) {
429
+ properties[f.key] = {
430
+ type
431
+ };
432
+ if (f.options.allowApiUpdate !== false) {
433
+ mutationProperties[f.key] = {
434
+ type
435
+ };
436
+ }
437
+ parameters.push({
438
+ "name": f.key,
439
+ "in": "query",
440
+ "description": "filter equal to " + f.key,
441
+ "required": false,
442
+ "style": "simple",
443
+ type
444
+ });
445
+ parameters.push({
446
+ "name": f.key + "_ne",
447
+ "in": "query",
448
+ "description": "filter not equal to " + f.key,
449
+ "required": false,
450
+ "style": "simple",
451
+ type
452
+ });
453
+ }
445
454
  }
446
455
  spec.components.schemas[key] = {
447
456
  type: "object",
448
457
  properties
449
458
  };
459
+ //TODO - handle allow api read also on the get level
460
+ if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
461
+ mutationKey += 'Mutation';
462
+ spec.components.schemas[mutationKey] = {
463
+ type: "object",
464
+ properties: mutationProperties
465
+ };
466
+ }
450
467
  let definition = {
451
468
  "$ref": "#/components/schemas/" + key
452
469
  };
@@ -456,8 +473,8 @@ export class RemultServerImplementation {
456
473
  condition = meta.options.allowApiCrud;
457
474
  return secureBase(condition, def, item);
458
475
  };
459
- let apiPath = spec.paths['/api/' + key] = {};
460
- let apiPathWithId = spec.paths['/api/' + key + "/{id}"] = {};
476
+ let apiPath = spec.paths[this.options.rootPath + '/' + key] = {};
477
+ let apiPathWithId = spec.paths[this.options.rootPath + '/' + key + "/{id}"] = {};
461
478
  //https://github.com/2fd/open-api.d.ts
462
479
  apiPath.get = secure(meta.options.allowApiRead, true, {
463
480
  description: "return an array of " + key + ". supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)",
@@ -516,7 +533,7 @@ export class RemultServerImplementation {
516
533
  "content": {
517
534
  "application/json": {
518
535
  "schema": {
519
- "$ref": "#/components/schemas/" + key
536
+ "$ref": "#/components/schemas/" + mutationKey
520
537
  }
521
538
  }
522
539
  }
package/graphql.js CHANGED
@@ -159,6 +159,8 @@ function remultGraphql(api) {
159
159
  return [2 /*return*/, new Promise(function (res, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
160
160
  var _this = this;
161
161
  return tslib_1.__generator(this, function (_a) {
162
+ if (req.req)
163
+ req = req.req; //TODO - yoga sends its own request object - and in it you get the original request (need to test with svelte and next)
162
164
  server.run(req, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
163
165
  var dApi, result, err;
164
166
  return tslib_1.__generator(this, function (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.20.3-exp.0",
3
+ "version": "0.20.3-exp.1",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -731,7 +731,9 @@ var RemultServerImplementation = /** @class */ (function () {
731
731
  var key = meta.key;
732
732
  var parameters = [];
733
733
  if (key) {
734
+ var mutationKey = key;
734
735
  var properties = {};
736
+ var mutationProperties = {};
735
737
  try {
736
738
  for (var _b = (e_7 = void 0, tslib_1.__values(meta.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
737
739
  var f = _c.value;
@@ -740,25 +742,32 @@ var RemultServerImplementation = /** @class */ (function () {
740
742
  f.valueType == Date ? "string" :
741
743
  f.valueType == Number ? "number" :
742
744
  "object";
743
- properties[f.key] = {
744
- type: type
745
- };
746
- parameters.push({
747
- "name": f.key,
748
- "in": "query",
749
- "description": "filter equal to " + f.key,
750
- "required": false,
751
- "style": "simple",
752
- type: type
753
- });
754
- parameters.push({
755
- "name": f.key + "_ne",
756
- "in": "query",
757
- "description": "filter not equal to " + f.key,
758
- "required": false,
759
- "style": "simple",
760
- type: type
761
- });
745
+ if (f.options.includeInApi !== false) {
746
+ properties[f.key] = {
747
+ type: type
748
+ };
749
+ if (f.options.allowApiUpdate !== false) {
750
+ mutationProperties[f.key] = {
751
+ type: type
752
+ };
753
+ }
754
+ parameters.push({
755
+ "name": f.key,
756
+ "in": "query",
757
+ "description": "filter equal to " + f.key,
758
+ "required": false,
759
+ "style": "simple",
760
+ type: type
761
+ });
762
+ parameters.push({
763
+ "name": f.key + "_ne",
764
+ "in": "query",
765
+ "description": "filter not equal to " + f.key,
766
+ "required": false,
767
+ "style": "simple",
768
+ type: type
769
+ });
770
+ }
762
771
  }
763
772
  }
764
773
  catch (e_7_1) { e_7 = { error: e_7_1 }; }
@@ -772,6 +781,14 @@ var RemultServerImplementation = /** @class */ (function () {
772
781
  type: "object",
773
782
  properties: properties
774
783
  };
784
+ //TODO - handle allow api read also on the get level
785
+ if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
786
+ mutationKey += 'Mutation';
787
+ spec.components.schemas[mutationKey] = {
788
+ type: "object",
789
+ properties: mutationProperties
790
+ };
791
+ }
775
792
  var definition = {
776
793
  "$ref": "#/components/schemas/" + key
777
794
  };
@@ -781,8 +798,8 @@ var RemultServerImplementation = /** @class */ (function () {
781
798
  condition = meta.options.allowApiCrud;
782
799
  return secureBase(condition, def, item);
783
800
  };
784
- var apiPath = spec.paths['/api/' + key] = {};
785
- var apiPathWithId = spec.paths['/api/' + key + "/{id}"] = {};
801
+ var apiPath = spec.paths[this_2.options.rootPath + '/' + key] = {};
802
+ var apiPathWithId = spec.paths[this_2.options.rootPath + '/' + key + "/{id}"] = {};
786
803
  //https://github.com/2fd/open-api.d.ts
787
804
  apiPath.get = secure(meta.options.allowApiRead, true, {
788
805
  description: "return an array of " + key + ". supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)",
@@ -841,7 +858,7 @@ var RemultServerImplementation = /** @class */ (function () {
841
858
  "content": {
842
859
  "application/json": {
843
860
  "schema": {
844
- "$ref": "#/components/schemas/" + key
861
+ "$ref": "#/components/schemas/" + mutationKey
845
862
  }
846
863
  }
847
864
  }
@@ -903,6 +920,7 @@ var RemultServerImplementation = /** @class */ (function () {
903
920
  });
904
921
  }
905
922
  };
923
+ var this_2 = this;
906
924
  try {
907
925
  for (var _c = tslib_1.__values(this.getEntities()), _d = _c.next(); !_d.done; _d = _c.next()) {
908
926
  var meta = _d.value;
@@ -1,3 +0,0 @@
1
- import type { RequestEvent, Handle } from '@sveltejs/kit';
2
- import { RemultServer, RemultServerOptions } from './server';
3
- export declare function remultSveltekit(options?: RemultServerOptions<RequestEvent>): RemultServer<RequestEvent> & Handle;
@@ -1,83 +0,0 @@
1
- import { createRemultServer } from './server';
2
- export function remultSveltekit(options) {
3
- let result = createRemultServer(options, {
4
- buildGenericRequest: event => ({
5
- url: event.request.url,
6
- method: event.request.method,
7
- body: event.locals["_tempJson"],
8
- on: (e, do1) => {
9
- if (e === 'close') {
10
- event.locals["_tempOnClose"] = do1;
11
- }
12
- }
13
- })
14
- });
15
- const handler = async ({ event, resolve }) => {
16
- if (event.url.pathname.startsWith(options.rootPath)) {
17
- let json = {};
18
- try {
19
- if (event.request.method == 'POST' || event.request.method == 'PUT') {
20
- json = await event.request.json();
21
- }
22
- }
23
- catch (error) {
24
- console.log(error);
25
- }
26
- let sseResponse = undefined;
27
- event.locals["_tempOnClose"] = () => { };
28
- const response = {
29
- end: () => { },
30
- json: () => { },
31
- status: () => {
32
- return response;
33
- },
34
- write: () => { },
35
- writeHead: (status, headers) => {
36
- if (status === 200 && headers) {
37
- const contentType = headers['Content-Type'];
38
- if (contentType === 'text/event-stream') {
39
- const messages = [];
40
- response.write = (x) => messages.push(x);
41
- const stream = new ReadableStream({
42
- start: (controller) => {
43
- for (const message of messages) {
44
- controller.enqueue(message);
45
- }
46
- response.write = (data) => {
47
- controller.enqueue(data);
48
- };
49
- },
50
- cancel: () => {
51
- response.write = () => { };
52
- event.locals["_tempOnClose"]();
53
- }
54
- });
55
- sseResponse = new Response(stream, { headers });
56
- }
57
- }
58
- }
59
- };
60
- event.locals["_tempJson"] = json;
61
- const responseFromRemultHandler = await result.handle(event, response);
62
- if (sseResponse !== undefined) {
63
- return sseResponse;
64
- }
65
- if (responseFromRemultHandler) {
66
- return new Response(JSON.stringify(responseFromRemultHandler.data), {
67
- status: responseFromRemultHandler.statusCode
68
- });
69
- }
70
- }
71
- return new Promise((res) => {
72
- result.withRemult(event, undefined, async () => {
73
- res(await resolve(event));
74
- });
75
- });
76
- };
77
- return Object.assign(handler, {
78
- getRemult: (req) => result.getRemult(req),
79
- openApiDoc: (options) => result.openApiDoc(options),
80
- registerRouter: x => result.registerRouter(x),
81
- withRemult: (...args) => result.withRemult(...args)
82
- });
83
- }