@zenstackhq/runtime 0.3.9 → 0.3.11

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.
Files changed (61) hide show
  1. package/{LICENSE.md → LICENSE} +0 -0
  2. package/client/index.d.ts +4 -0
  3. package/client/index.js +7 -0
  4. package/lib/client.d.ts +3 -0
  5. package/lib/client.js +34 -0
  6. package/lib/client.js.map +1 -0
  7. package/lib/config.d.ts +14 -0
  8. package/lib/config.js +3 -0
  9. package/lib/config.js.map +1 -0
  10. package/lib/constants.d.ts +12 -0
  11. package/lib/constants.js +16 -0
  12. package/lib/constants.js.map +1 -0
  13. package/lib/handler/data/handler.d.ts +19 -0
  14. package/lib/handler/data/handler.js +306 -0
  15. package/lib/handler/data/handler.js.map +1 -0
  16. package/lib/handler/data/nested-write-vistor.d.ts +31 -0
  17. package/lib/handler/data/nested-write-vistor.js +67 -0
  18. package/lib/handler/data/nested-write-vistor.js.map +1 -0
  19. package/lib/handler/data/policy-utils.d.ts +73 -0
  20. package/lib/handler/data/policy-utils.js +477 -0
  21. package/lib/handler/data/policy-utils.js.map +1 -0
  22. package/lib/handler/index.d.ts +1 -0
  23. package/lib/handler/index.js +9 -0
  24. package/lib/handler/index.js.map +1 -0
  25. package/lib/handler/types.d.ts +28 -0
  26. package/lib/handler/types.js +36 -0
  27. package/lib/handler/types.js.map +1 -0
  28. package/lib/index.d.ts +5 -0
  29. package/lib/index.js +22 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/request-handler.d.ts +21 -0
  32. package/lib/request-handler.js +37 -0
  33. package/lib/request-handler.js.map +1 -0
  34. package/lib/request.d.ts +16 -0
  35. package/lib/request.js +171 -0
  36. package/lib/request.js.map +1 -0
  37. package/lib/service.d.ts +32 -0
  38. package/lib/service.js +185 -0
  39. package/lib/service.js.map +1 -0
  40. package/lib/types.d.ts +168 -0
  41. package/lib/types.js +59 -0
  42. package/lib/types.js.map +1 -0
  43. package/lib/validation.d.ts +12 -0
  44. package/lib/validation.js +26 -0
  45. package/lib/validation.js.map +1 -0
  46. package/package.json +32 -7
  47. package/{auth.d.ts → server/auth.d.ts} +0 -0
  48. package/{auth.js → server/auth.js} +0 -0
  49. package/server/index.d.ts +16 -0
  50. package/server/index.js +7 -0
  51. package/{types.d.ts → types/index.d.ts} +0 -0
  52. package/{types.js → types/index.js} +0 -0
  53. package/README.md +0 -5
  54. package/client.d.ts +0 -1
  55. package/client.js +0 -3
  56. package/hooks.d.ts +0 -10
  57. package/hooks.js +0 -3
  58. package/index.d.ts +0 -3
  59. package/index.js +0 -1
  60. package/server.d.ts +0 -1
  61. package/server.js +0 -3
package/lib/types.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getServerErrorMessage = exports.ServerErrorCode = void 0;
4
+ /**
5
+ * Error codes for errors on server side
6
+ */
7
+ var ServerErrorCode;
8
+ (function (ServerErrorCode) {
9
+ /**
10
+ * The specified entity cannot be found
11
+ */
12
+ ServerErrorCode["ENTITY_NOT_FOUND"] = "ENTITY_NOT_FOUND";
13
+ /**
14
+ * The request parameter is invalid, either containing invalid fields or missing required fields
15
+ */
16
+ ServerErrorCode["INVALID_REQUEST_PARAMS"] = "INVALID_REQUEST_PARAMS";
17
+ /**
18
+ * The request is rejected by policy checks
19
+ */
20
+ ServerErrorCode["DENIED_BY_POLICY"] = "DENIED_BY_POLICY";
21
+ /**
22
+ * Violation of database unique constraints
23
+ */
24
+ ServerErrorCode["UNIQUE_CONSTRAINT_VIOLATION"] = "UNIQUE_CONSTRAINT_VIOLATION";
25
+ /**
26
+ * Violation of database reference constraint (aka. foreign key constraints)
27
+ */
28
+ ServerErrorCode["REFERENCE_CONSTRAINT_VIOLATION"] = "REFERENCE_CONSTRAINT_VIOLATION";
29
+ /**
30
+ * A write operation succeeded but the result cannot be read back due to policy control
31
+ */
32
+ ServerErrorCode["READ_BACK_AFTER_WRITE_DENIED"] = "READ_BACK_AFTER_WRITE_DENIED";
33
+ /**
34
+ * Unknown error
35
+ */
36
+ ServerErrorCode["UNKNOWN"] = "UNKNOWN";
37
+ })(ServerErrorCode = exports.ServerErrorCode || (exports.ServerErrorCode = {}));
38
+ function getServerErrorMessage(code) {
39
+ switch (code) {
40
+ case ServerErrorCode.ENTITY_NOT_FOUND:
41
+ return 'the requested entity is not found';
42
+ case ServerErrorCode.INVALID_REQUEST_PARAMS:
43
+ return 'request parameters are invalid';
44
+ case ServerErrorCode.DENIED_BY_POLICY:
45
+ return 'the request was denied due to access policy violation';
46
+ case ServerErrorCode.UNIQUE_CONSTRAINT_VIOLATION:
47
+ return 'the request failed because of database unique constraint violation';
48
+ case ServerErrorCode.REFERENCE_CONSTRAINT_VIOLATION:
49
+ return 'the request failed because of database foreign key constraint violation';
50
+ case ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED:
51
+ return 'the write operation succeeded, but the data cannot be read back due to access policy violation';
52
+ case ServerErrorCode.UNKNOWN:
53
+ return 'an unknown error occurred';
54
+ default:
55
+ return `generic error: ${code}`;
56
+ }
57
+ }
58
+ exports.getServerErrorMessage = getServerErrorMessage;
59
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAqIA;;GAEG;AACH,IAAY,eAmCX;AAnCD,WAAY,eAAe;IACvB;;OAEG;IACH,wDAAqC,CAAA;IAErC;;OAEG;IACH,oEAAiD,CAAA;IAEjD;;OAEG;IACH,wDAAqC,CAAA;IAErC;;OAEG;IACH,8EAA2D,CAAA;IAE3D;;OAEG;IACH,oFAAiE,CAAA;IAEjE;;OAEG;IACH,gFAA6D,CAAA;IAE7D;;OAEG;IACH,sCAAmB,CAAA;AACvB,CAAC,EAnCW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAmC1B;AAED,SAAgB,qBAAqB,CAAC,IAAqB;IACvD,QAAQ,IAAI,EAAE;QACV,KAAK,eAAe,CAAC,gBAAgB;YACjC,OAAO,mCAAmC,CAAC;QAE/C,KAAK,eAAe,CAAC,sBAAsB;YACvC,OAAO,gCAAgC,CAAC;QAE5C,KAAK,eAAe,CAAC,gBAAgB;YACjC,OAAO,uDAAuD,CAAC;QAEnE,KAAK,eAAe,CAAC,2BAA2B;YAC5C,OAAO,oEAAoE,CAAC;QAEhF,KAAK,eAAe,CAAC,8BAA8B;YAC/C,OAAO,yEAAyE,CAAC;QAErF,KAAK,eAAe,CAAC,4BAA4B;YAC7C,OAAO,gGAAgG,CAAC;QAE5G,KAAK,eAAe,CAAC,OAAO;YACxB,OAAO,2BAA2B,CAAC;QAEvC;YACI,OAAO,kBAAkB,IAAI,EAAE,CAAC;KACvC;AACL,CAAC;AA1BD,sDA0BC"}
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Error indicating violations of field-level constraints
4
+ */
5
+ export declare class ValidationError {
6
+ readonly message: string;
7
+ constructor(message: string);
8
+ }
9
+ /**
10
+ * Validate the given data with the given zod schema (for field-level constraints)
11
+ */
12
+ export declare function validate(validator: z.ZodType, data: unknown): void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validate = exports.ValidationError = void 0;
4
+ const zod_validation_error_1 = require("zod-validation-error");
5
+ /**
6
+ * Error indicating violations of field-level constraints
7
+ */
8
+ class ValidationError {
9
+ constructor(message) {
10
+ this.message = message;
11
+ }
12
+ }
13
+ exports.ValidationError = ValidationError;
14
+ /**
15
+ * Validate the given data with the given zod schema (for field-level constraints)
16
+ */
17
+ function validate(validator, data) {
18
+ try {
19
+ validator.parse(data);
20
+ }
21
+ catch (err) {
22
+ throw new ValidationError((0, zod_validation_error_1.fromZodError)(err).message);
23
+ }
24
+ }
25
+ exports.validate = validate;
26
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":";;;AACA,+DAAoD;AAEpD;;GAEG;AACH,MAAa,eAAe;IACxB,YAA4B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;CAClD;AAFD,0CAEC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,SAAoB,EAAE,IAAa;IACxD,IAAI;QACA,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACzB;IAAC,OAAO,GAAG,EAAE;QACV,MAAM,IAAI,eAAe,CAAC,IAAA,mCAAY,EAAC,GAAiB,CAAC,CAAC,OAAO,CAAC,CAAC;KACtE;AACL,CAAC;AAND,4BAMC"}
package/package.json CHANGED
@@ -1,23 +1,48 @@
1
1
  {
2
2
  "name": "@zenstackhq/runtime",
3
3
  "displayName": "ZenStack Runtime Library",
4
- "version": "0.3.9",
5
- "description": "This package contains runtime library for consuming client and server side code generated by ZenStack.",
4
+ "version": "0.3.11",
5
+ "description": "Runtime of ZenStack for both client-side and server-side environments.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/zenstackhq/zenstack"
9
9
  },
10
- "main": "index.js",
11
- "types": "index.d.ts",
10
+ "publishConfig": {
11
+ "directory": "dist"
12
+ },
12
13
  "dependencies": {
13
- "@zenstackhq/internal": "latest"
14
+ "colors": "1.4.0",
15
+ "cuid": "^2.1.8",
16
+ "decimal.js": "^10.4.2",
17
+ "deepcopy": "^2.1.0",
18
+ "swr": "^1.3.0",
19
+ "tslib": "^2.4.1",
20
+ "zod": "^3.19.1",
21
+ "zod-validation-error": "^0.2.1"
14
22
  },
15
23
  "peerDependencies": {
16
24
  "@types/bcryptjs": "^2.4.2",
17
- "bcryptjs": "^2.4.3"
25
+ "bcryptjs": "^2.4.3",
26
+ "next": "^12.3.1",
27
+ "react": "^17.0.2 || ^18",
28
+ "react-dom": "^17.0.2 || ^18"
18
29
  },
19
30
  "author": {
20
31
  "name": "ZenStack Team"
21
32
  },
22
- "license": "MIT"
33
+ "license": "MIT",
34
+ "devDependencies": {
35
+ "@types/bcryptjs": "^2.4.2",
36
+ "@types/jest": "^29.0.3",
37
+ "@types/node": "^14.18.29",
38
+ "rimraf": "^3.0.2",
39
+ "typescript": "^4.9.3"
40
+ },
41
+ "scripts": {
42
+ "clean": "rimraf dist",
43
+ "build": "npm run clean && tsc && cp -r pre/* dist/ && cp ./package.json dist/",
44
+ "watch": "tsc --watch",
45
+ "lint": "eslint src --ext ts",
46
+ "publish-dev": "pnpm publish --tag dev"
47
+ }
23
48
  }
File without changes
File without changes
@@ -0,0 +1,16 @@
1
+ import service from '.zenstack/lib';
2
+
3
+ export type {
4
+ FieldInfo,
5
+ PolicyKind,
6
+ PolicyOperationKind,
7
+ RuntimeAttribute,
8
+ QueryContext,
9
+ } from '../lib/types';
10
+
11
+ export {
12
+ requestHandler,
13
+ type RequestHandlerOptions,
14
+ } from '../lib/request-handler';
15
+
16
+ export default service;
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ exports.default = require('.zenstack/lib').default;
4
+
5
+ const exportStar = require('tslib').__exportStar;
6
+ exportStar(require('../lib/types'), exports);
7
+ exportStar(require('../lib/request-handler'), exports);
File without changes
File without changes
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # ZenStack Runtime Library
2
-
3
- This package is the runtime library supporting web apps built using ZenStack.
4
-
5
- Visit [Homepage](https://github.com/zenstackhq/zenstack#readme) for more details.
package/client.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@zenstackhq/internal/lib/client';
package/client.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- ...require('@zenstackhq/internal/lib/client'),
3
- };
package/hooks.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { ServerErrorCode } from './client';
2
-
3
- export * from '.zenstack/lib/hooks';
4
- export type HooksError = {
5
- status: number;
6
- info: {
7
- code: ServerErrorCode;
8
- message: string;
9
- };
10
- };
package/hooks.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- ...require('.zenstack/lib/hooks'),
3
- };
package/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from '.zenstack/lib';
2
- import service from '.zenstack/lib';
3
- export default service;
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('.zenstack/lib').default;
package/server.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@zenstackhq/internal';
package/server.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- ...require('@zenstackhq/internal'),
3
- };