@teamkeel/functions-runtime 0.411.0 → 0.412.0-next.2

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 (49) hide show
  1. package/dist/index.d.mts +340 -0
  2. package/dist/index.d.ts +340 -0
  3. package/dist/index.js +3093 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +3097 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +23 -5
  8. package/.env.test +0 -2
  9. package/compose.yaml +0 -10
  10. package/src/Duration.js +0 -40
  11. package/src/Duration.test.js +0 -34
  12. package/src/File.js +0 -295
  13. package/src/ModelAPI.js +0 -377
  14. package/src/ModelAPI.test.js +0 -1428
  15. package/src/QueryBuilder.js +0 -184
  16. package/src/QueryContext.js +0 -90
  17. package/src/RequestHeaders.js +0 -21
  18. package/src/TimePeriod.js +0 -89
  19. package/src/TimePeriod.test.js +0 -148
  20. package/src/applyAdditionalQueryConstraints.js +0 -22
  21. package/src/applyJoins.js +0 -67
  22. package/src/applyWhereConditions.js +0 -124
  23. package/src/auditing.js +0 -110
  24. package/src/auditing.test.js +0 -330
  25. package/src/camelCasePlugin.js +0 -52
  26. package/src/casing.js +0 -54
  27. package/src/casing.test.js +0 -56
  28. package/src/consts.js +0 -14
  29. package/src/database.js +0 -244
  30. package/src/errors.js +0 -160
  31. package/src/handleJob.js +0 -110
  32. package/src/handleJob.test.js +0 -270
  33. package/src/handleRequest.js +0 -153
  34. package/src/handleRequest.test.js +0 -463
  35. package/src/handleRoute.js +0 -112
  36. package/src/handleSubscriber.js +0 -105
  37. package/src/index.d.ts +0 -317
  38. package/src/index.js +0 -38
  39. package/src/parsing.js +0 -113
  40. package/src/parsing.test.js +0 -140
  41. package/src/permissions.js +0 -77
  42. package/src/permissions.test.js +0 -118
  43. package/src/tracing.js +0 -184
  44. package/src/tracing.test.js +0 -147
  45. package/src/tryExecuteFunction.js +0 -91
  46. package/src/tryExecuteJob.js +0 -29
  47. package/src/tryExecuteSubscriber.js +0 -17
  48. package/src/type-utils.js +0 -18
  49. package/vite.config.js +0 -7
@@ -1,77 +0,0 @@
1
- const { AsyncLocalStorage } = require("async_hooks");
2
- const { PermissionError } = require("./errors");
3
-
4
- const PERMISSION_STATE = {
5
- UNKNOWN: "unknown",
6
- PERMITTED: "permitted",
7
- UNPERMITTED: "unpermitted",
8
- };
9
-
10
- // withPermissions sets the initial permission state from the go runtime in the AsyncLocalStorage so consumers further down the hierarchy can read or mutate the state
11
- // at will
12
- const withPermissions = async (initialValue, cb) => {
13
- const permissions = new Permissions();
14
-
15
- return await permissionsApiInstance.run({ permitted: initialValue }, () => {
16
- return cb({ getPermissionState: permissions.getState });
17
- });
18
- };
19
-
20
- const permissionsApiInstance = new AsyncLocalStorage();
21
-
22
- class Permissions {
23
- // The Go runtime performs role based permission rule checks prior to calling the functions
24
- // runtime, so the status could already be granted. If already granted, then we need to inherit that permission state as the state is later used to decide whether to run in process permission checks
25
- // TLDR if a role based permission is relevant and it is granted, then it is effectively the same as the end user calling api.permissions.allow() explicitly in terms of behaviour.
26
-
27
- allow() {
28
- const store = (permissionsApiInstance.getStore().permitted = true);
29
- }
30
-
31
- deny() {
32
- // if a user is explicitly calling deny() then we want to throw an error
33
- // so that any further execution of the custom function stops abruptly
34
- permissionsApiInstance.getStore().permitted = false;
35
-
36
- throw new PermissionError();
37
- }
38
-
39
- getState() {
40
- const permitted = permissionsApiInstance.getStore().permitted;
41
-
42
- switch (true) {
43
- case permitted === false:
44
- return PERMISSION_STATE.UNPERMITTED;
45
- case permitted === null:
46
- return PERMISSION_STATE.UNKNOWN;
47
- case permitted === true:
48
- return PERMISSION_STATE.PERMITTED;
49
- }
50
- }
51
- }
52
-
53
- const checkBuiltInPermissions = async ({
54
- rows,
55
- permissionFns,
56
- ctx,
57
- db,
58
- functionName,
59
- }) => {
60
- for (const permissionFn of permissionFns) {
61
- const result = await permissionFn(rows, ctx, db);
62
- // if any of the permission functions return true,
63
- // then we return early
64
- if (result) {
65
- return;
66
- }
67
- }
68
-
69
- throw new PermissionError(`Not permitted to access ${functionName}`);
70
- };
71
-
72
- module.exports.checkBuiltInPermissions = checkBuiltInPermissions;
73
- module.exports.PermissionError = PermissionError;
74
- module.exports.PERMISSION_STATE = PERMISSION_STATE;
75
- module.exports.Permissions = Permissions;
76
- module.exports.withPermissions = withPermissions;
77
- module.exports.permissionsApiInstance = permissionsApiInstance;
@@ -1,118 +0,0 @@
1
- const {
2
- permissionsApiInstance,
3
- Permissions,
4
- PERMISSION_STATE,
5
- checkBuiltInPermissions,
6
- } = require("./permissions");
7
- import { useDatabase } from "./database";
8
- import { beforeEach, describe, expect, test } from "vitest";
9
- const { PermissionError } = require("./errors");
10
-
11
- let permissions;
12
- let ctx = {};
13
- let db = useDatabase();
14
-
15
- describe("explicit", () => {
16
- beforeEach(() => {
17
- permissions = new Permissions();
18
- });
19
-
20
- test("explicitly allowing execution", () => {
21
- wrapWithAsyncLocalStorage({ permitted: null }, () => {
22
- expect(permissions.getState()).toEqual(PERMISSION_STATE.UNKNOWN);
23
-
24
- permissions.allow();
25
-
26
- expect(permissions.getState()).toEqual(PERMISSION_STATE.PERMITTED);
27
- });
28
- });
29
-
30
- test("explicitly denying execution", () => {
31
- wrapWithAsyncLocalStorage({ permitted: null }, () => {
32
- expect(permissions.getState()).toEqual(PERMISSION_STATE.UNKNOWN);
33
-
34
- expect(() => permissions.deny()).toThrowError(PermissionError);
35
-
36
- expect(permissions.getState()).toEqual(PERMISSION_STATE.UNPERMITTED);
37
- });
38
- });
39
- });
40
-
41
- describe("prior state", () => {
42
- test("when the prior state is granted", () => {
43
- wrapWithAsyncLocalStorage(
44
- {
45
- permitted: true,
46
- },
47
- () => {
48
- expect(permissions.getState()).toEqual(PERMISSION_STATE.PERMITTED);
49
- }
50
- );
51
- });
52
- });
53
-
54
- describe("check", () => {
55
- const functionName = "createPerson";
56
-
57
- test("check - success", async () => {
58
- const permissionRule1 = (records, ctx, db) => {
59
- // Only allow names starting with Adam
60
- return records.every((r) => r.name.startsWith("Adam"));
61
- };
62
-
63
- const rows = [
64
- {
65
- id: "123",
66
- name: "Adam Bull",
67
- },
68
- {
69
- id: "234",
70
- name: "Adam Lambert",
71
- },
72
- ];
73
-
74
- await expect(
75
- checkBuiltInPermissions({
76
- rows,
77
- ctx,
78
- db,
79
- functionName,
80
- permissionFns: [permissionRule1],
81
- })
82
- ).resolves.ok;
83
- });
84
-
85
- test("check - failure", async () => {
86
- // only allow Petes
87
- const permissionRule1 = (records, ctx, db) => {
88
- return records.every((r) => r.name === "Pete");
89
- };
90
-
91
- const rows = [
92
- {
93
- id: "123",
94
- name: "Adam", // this one will cause an error to be thrown because Adam is not Pete
95
- },
96
- {
97
- id: "234",
98
- name: "Pete",
99
- },
100
- ];
101
-
102
- await expect(
103
- checkBuiltInPermissions({
104
- rows,
105
- ctx,
106
- db,
107
- functionName,
108
- permissionFns: [permissionRule1],
109
- })
110
- ).rejects.toThrow();
111
- });
112
- });
113
-
114
- function wrapWithAsyncLocalStorage(initialState, testFn) {
115
- permissionsApiInstance.run(initialState, () => {
116
- testFn();
117
- });
118
- }
package/src/tracing.js DELETED
@@ -1,184 +0,0 @@
1
- const opentelemetry = require("@opentelemetry/api");
2
- const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base");
3
- const {
4
- OTLPTraceExporter,
5
- } = require("@opentelemetry/exporter-trace-otlp-proto");
6
- const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
7
- const { envDetectorSync } = require("@opentelemetry/resources");
8
-
9
- async function withSpan(name, fn) {
10
- return getTracer().startActiveSpan(name, async (span) => {
11
- try {
12
- // await the thing (this means we can use try/catch)
13
- return await fn(span);
14
- } catch (err) {
15
- // record any errors
16
- span.recordException(err);
17
- span.setStatus({
18
- code: opentelemetry.SpanStatusCode.ERROR,
19
- message: err.message,
20
- });
21
- // re-throw the error
22
- throw err;
23
- } finally {
24
- // make sure the span is ended
25
- span.end();
26
- }
27
- });
28
- }
29
-
30
- function patchFetch() {
31
- if (!globalThis.fetch.patched) {
32
- const originalFetch = globalThis.fetch;
33
-
34
- globalThis.fetch = async (...args) => {
35
- return withSpan("fetch", async (span) => {
36
- const url = new URL(
37
- args[0] instanceof Request ? args[0].url : String(args[0])
38
- );
39
- span.setAttribute("http.url", url.toString());
40
- const scheme = url.protocol.replace(":", "");
41
- span.setAttribute("http.scheme", scheme);
42
-
43
- const options = args[0] instanceof Request ? args[0] : args[1] || {};
44
- const method = (options.method || "GET").toUpperCase();
45
- span.setAttribute("http.method", method);
46
-
47
- const res = await originalFetch(...args);
48
- span.setAttribute("http.status", res.status);
49
- span.setAttribute("http.status_text", res.statusText);
50
- return res;
51
- });
52
- };
53
- globalThis.fetch.patched = true;
54
- }
55
- }
56
-
57
- function patchConsoleLog() {
58
- if (!console.log.patched) {
59
- const originalConsoleLog = console.log;
60
-
61
- console.log = (...args) => {
62
- const span = opentelemetry.trace.getActiveSpan();
63
- if (span) {
64
- const output = args
65
- .map((arg) => {
66
- if (arg instanceof Error) {
67
- return arg.stack;
68
- }
69
- if (typeof arg === "object") {
70
- try {
71
- return JSON.stringify(arg, getCircularReplacer());
72
- } catch (error) {
73
- return "[Object with circular references]";
74
- }
75
- }
76
- if (typeof arg === "function") {
77
- return arg() || arg.name || arg.toString();
78
- }
79
- return String(arg);
80
- })
81
- .join(" ");
82
-
83
- span.addEvent(output);
84
- }
85
- originalConsoleLog(...args);
86
- };
87
-
88
- console.log.patched = true;
89
- }
90
- }
91
-
92
- function patchConsoleError() {
93
- if (!console.error.patched) {
94
- const originalConsoleError = console.error;
95
-
96
- console.error = (...args) => {
97
- const span = opentelemetry.trace.getActiveSpan();
98
- if (span) {
99
- const output = args
100
- .map((arg) => {
101
- if (arg instanceof Error) {
102
- return arg.stack;
103
- }
104
- if (typeof arg === "object") {
105
- try {
106
- return JSON.stringify(arg, getCircularReplacer());
107
- } catch (error) {
108
- return "[Object with circular references]";
109
- }
110
- }
111
- if (typeof arg === "function") {
112
- return arg() || arg.name || arg.toString();
113
- }
114
- return String(arg);
115
- })
116
- .join(" ");
117
-
118
- span.setStatus({
119
- code: opentelemetry.SpanStatusCode.ERROR,
120
- message: output,
121
- });
122
- }
123
- originalConsoleError(...args);
124
- };
125
-
126
- console.error.patched = true;
127
- }
128
- }
129
-
130
- // Utility to handle circular references in objects
131
- function getCircularReplacer() {
132
- const seen = new WeakSet();
133
- return (key, value) => {
134
- if (typeof value === "object" && value !== null) {
135
- if (seen.has(value)) {
136
- return "[Circular]";
137
- }
138
- seen.add(value);
139
- }
140
- return value;
141
- };
142
- }
143
-
144
- function init() {
145
- if (process.env.KEEL_TRACING_ENABLED == "true") {
146
- const exporter = new OTLPTraceExporter();
147
- const processor = new BatchSpanProcessor(exporter);
148
-
149
- const provider = new NodeTracerProvider({
150
- resource: envDetectorSync.detect(),
151
- spanProcessors: [processor],
152
- });
153
-
154
- provider.register();
155
- }
156
-
157
- patchFetch();
158
- patchConsoleLog();
159
- patchConsoleError();
160
- }
161
-
162
- async function forceFlush() {
163
- // The "delegate" is the actual provider set by the functions-runtime package
164
- const provider = opentelemetry.trace.getTracerProvider().getDelegate();
165
- if (provider && provider.forceFlush) {
166
- await provider.forceFlush();
167
- }
168
- }
169
-
170
- function getTracer() {
171
- return opentelemetry.trace.getTracer("functions");
172
- }
173
-
174
- function spanNameForModelAPI(modelName, action) {
175
- return `Database ${modelName}.${action}`;
176
- }
177
-
178
- module.exports = {
179
- getTracer,
180
- withSpan,
181
- init,
182
- forceFlush,
183
- spanNameForModelAPI,
184
- };
@@ -1,147 +0,0 @@
1
- import { expect, test, beforeEach } from "vitest";
2
- import tracing from "./tracing";
3
- import { NodeTracerProvider, Span } from "@opentelemetry/sdk-trace-node";
4
- const opentelemetry = require("@opentelemetry/api");
5
-
6
- let spanEvents = [];
7
- const provider = new NodeTracerProvider({
8
- spanProcessors: [
9
- {
10
- forceFlush() {
11
- return Promise.resolve();
12
- },
13
- onStart(span, parentContext) {
14
- spanEvents.push({ event: "onStart", span, parentContext });
15
- },
16
- onEnd(span) {
17
- spanEvents.push({ event: "onEnd", span });
18
- },
19
- shutdown() {
20
- return Promise.resolve();
21
- },
22
- },
23
- ],
24
- });
25
- provider.register();
26
-
27
- beforeEach(() => {
28
- tracing.init();
29
- spanEvents = [];
30
- });
31
-
32
- test("withSpan span time", async () => {
33
- const waitTimeMillis = 100;
34
- await tracing.withSpan("name", async () => {
35
- await new Promise((resolve) => setTimeout(resolve, waitTimeMillis));
36
- });
37
-
38
- expect(spanEvents.map((e) => e.event)).toEqual(["onStart", "onEnd"]);
39
- const spanDuration = spanEvents.pop().span._duration.pop();
40
-
41
- // The '- 1' here is because sometimes the test fails due to the span duration
42
- // being something like 99.87ms. As long as it's at least 99ms we're happy
43
- const waitTimeNanos = (waitTimeMillis - 1) * 1000 * 1000;
44
- expect(spanDuration).toBeGreaterThan(waitTimeNanos);
45
- });
46
-
47
- test("withSpan on error", async () => {
48
- try {
49
- await tracing.withSpan("name", async () => {
50
- throw "err";
51
- });
52
- // previous line should have an error thrown
53
- expect(true).toEqual(false);
54
- } catch (e) {
55
- expect(e).toEqual("err");
56
- expect(spanEvents.map((e) => e.event)).toEqual(["onStart", "onEnd"]);
57
- const lastSpanEvents = spanEvents.pop().span.events;
58
- expect(lastSpanEvents).length(1);
59
- expect(lastSpanEvents[0].name).toEqual("exception");
60
- expect(lastSpanEvents[0].attributes).toEqual({
61
- "exception.message": "err",
62
- });
63
- }
64
- });
65
-
66
- test("withSpan console.log", async () => {
67
- await tracing.withSpan("name", async () => {
68
- console.log("test log");
69
- });
70
-
71
- const span = spanEvents.pop().span;
72
- expect(span.events).toHaveLength(1);
73
- expect(span.events[0].name).toEqual("test log");
74
- });
75
-
76
- test("withSpan console.error", async () => {
77
- await tracing.withSpan("name", async () => {
78
- console.error("test error");
79
- });
80
-
81
- const span = spanEvents.pop().span;
82
- expect(span.events).toHaveLength(0);
83
- expect(span.status.code).toEqual(opentelemetry.SpanStatusCode.ERROR);
84
- expect(span.status.message).toEqual("test error");
85
- });
86
-
87
- test("fetch - 200", async () => {
88
- const res = await fetch("http://example.com");
89
- expect(res.status).toEqual(200);
90
-
91
- expect(spanEvents.map((e) => e.event)).toEqual(["onStart", "onEnd"]);
92
- expect(spanEvents.pop().span.attributes).toEqual({
93
- "http.url": "http://example.com/",
94
- "http.scheme": "http",
95
- "http.method": "GET",
96
- "http.status": 200,
97
- "http.status_text": "OK",
98
- });
99
- });
100
-
101
- test("fetch - 404", async () => {
102
- await fetch("https://keel.so/not-found");
103
-
104
- expect(spanEvents.map((e) => e.event)).toEqual(["onStart", "onEnd"]);
105
- expect(spanEvents.pop().span.attributes).toEqual({
106
- "http.url": "https://keel.so/not-found",
107
- "http.scheme": "https",
108
- "http.method": "GET",
109
- "http.status": 404,
110
- "http.status_text": "Not Found",
111
- });
112
- });
113
-
114
- test("fetch - invalid URL", async () => {
115
- try {
116
- await fetch({});
117
- } catch (err) {
118
- expect(err.message).toEqual("Invalid URL");
119
- }
120
-
121
- expect(spanEvents.map((e) => e.event)).toEqual(["onStart", "onEnd"]);
122
-
123
- const span = spanEvents.pop().span;
124
- expect(spanEvents.pop().span.attributes).toEqual({});
125
- expect(span.events[0].name).toEqual("exception");
126
- expect.assertions(4);
127
- });
128
-
129
- test("fetch - ENOTFOUND", async () => {
130
- try {
131
- await fetch("http://qpwoeuthnvksnvnsanrurvnc.com");
132
- } catch (err) {
133
- expect(err.message).toEqual("fetch failed");
134
- expect(err.cause.code).toEqual("ENOTFOUND");
135
- }
136
-
137
- expect(spanEvents.map((e) => e.event)).toEqual(["onStart", "onEnd"]);
138
-
139
- const span = spanEvents.pop().span;
140
- expect(span.attributes).toEqual({
141
- "http.method": "GET",
142
- "http.scheme": "http",
143
- "http.url": "http://qpwoeuthnvksnvnsanrurvnc.com/",
144
- });
145
- expect(span.events[0].name).toEqual("exception");
146
- expect.assertions(5);
147
- });
@@ -1,91 +0,0 @@
1
- const { withDatabase } = require("./database");
2
- const { withAuditContext } = require("./auditing");
3
- const {
4
- withPermissions,
5
- PERMISSION_STATE,
6
- checkBuiltInPermissions,
7
- } = require("./permissions");
8
- const { PermissionError } = require("./errors");
9
- const { PROTO_ACTION_TYPES } = require("./consts");
10
-
11
- // tryExecuteFunction will create a new database transaction around a function call
12
- // and handle any permissions checks. If a permission check fails, then an Error will be thrown and the catch block will be hit.
13
- function tryExecuteFunction(
14
- { request, db, permitted, permissionFns, actionType, ctx, functionConfig },
15
- cb
16
- ) {
17
- return withPermissions(permitted, async ({ getPermissionState }) => {
18
- let requiresTransaction = true;
19
- switch (actionType) {
20
- case PROTO_ACTION_TYPES.GET:
21
- case PROTO_ACTION_TYPES.LIST:
22
- case PROTO_ACTION_TYPES.READ:
23
- requiresTransaction = false;
24
- break;
25
- }
26
-
27
- if (functionConfig?.dbTransaction !== undefined) {
28
- requiresTransaction = functionConfig.dbTransaction;
29
- }
30
-
31
- return withDatabase(db, requiresTransaction, async ({ transaction }) => {
32
- const fnResult = await withAuditContext(request, async () => {
33
- return cb();
34
- });
35
-
36
- // api.permissions maintains an internal state of whether the current function has been *explicitly* permitted/denied by the user in the course of their custom function, or if execution has already been permitted by a role based permission (evaluated in the main runtime).
37
- // we need to check that the final state is permitted or unpermitted. if it's not, then it means that the user has taken no explicit action to permit/deny
38
- // and therefore we default to checking the permissions defined in the schema automatically.
39
- switch (getPermissionState()) {
40
- case PERMISSION_STATE.PERMITTED:
41
- return fnResult;
42
- case PERMISSION_STATE.UNPERMITTED:
43
- throw new PermissionError(
44
- `Not permitted to access ${request.method}`
45
- );
46
- default:
47
- // unknown state, proceed with checking against the built in permissions in the schema
48
- const relevantPermissions = permissionFns[request.method];
49
-
50
- const peakInsideTransaction =
51
- actionType === PROTO_ACTION_TYPES.CREATE;
52
-
53
- let rowsForPermissions = [];
54
- if (fnResult != null) {
55
- switch (actionType) {
56
- case PROTO_ACTION_TYPES.LIST:
57
- rowsForPermissions = fnResult;
58
- break;
59
- case PROTO_ACTION_TYPES.DELETE:
60
- rowsForPermissions = [{ id: fnResult }];
61
- break;
62
- case (PROTO_ACTION_TYPES.GET, PROTO_ACTION_TYPES.CREATE):
63
- rowsForPermissions = [fnResult];
64
- break;
65
- default:
66
- rowsForPermissions = [fnResult];
67
- break;
68
- }
69
- }
70
-
71
- // check will throw a PermissionError if a permission rule is invalid
72
- await checkBuiltInPermissions({
73
- rows: rowsForPermissions,
74
- permissionFns: relevantPermissions,
75
- // it is important that we pass db here as db represents the connection to the database
76
- // *outside* of the current transaction. Given that any changes inside of a transaction
77
- // are opaque to the outside, we can utilize this when running permission rules and then deciding to
78
- // rollback any changes if they do not pass. However, for creates we need to be able to 'peak' inside the transaction to read the created record, as this won't exist outside of the transaction.
79
- db: peakInsideTransaction ? transaction : db,
80
- ctx,
81
- functionName: request.method,
82
- });
83
-
84
- // If the built in permission check above doesn't throw, then it means that the request is permitted and we can continue returning the return value from the custom function out of the transaction
85
- return fnResult;
86
- }
87
- });
88
- });
89
- }
90
-
91
- module.exports.tryExecuteFunction = tryExecuteFunction;
@@ -1,29 +0,0 @@
1
- const { withDatabase } = require("./database");
2
- const { withAuditContext } = require("./auditing");
3
- const { withPermissions, PERMISSION_STATE } = require("./permissions");
4
- const { PermissionError } = require("./errors");
5
-
6
- // tryExecuteJob will create a new database transaction around a function call
7
- // and handle any permissions checks. If a permission check fails, then an Error will be thrown and the catch block will be hit.
8
- function tryExecuteJob({ db, permitted, request, functionConfig }, cb) {
9
- return withPermissions(permitted, async ({ getPermissionState }) => {
10
- let requiresTransaction = false;
11
- if (functionConfig?.dbTransaction !== undefined) {
12
- requiresTransaction = functionConfig.dbTransaction;
13
- }
14
- return withDatabase(db, requiresTransaction, async () => {
15
- await withAuditContext(request, async () => {
16
- return cb();
17
- });
18
-
19
- // api.permissions maintains an internal state of whether the current operation has been *explicitly* permitted/denied by the user in the course of their custom function, or if execution has already been permitted by a role based permission (evaluated in the main runtime).
20
- // we need to check that the final state is permitted or unpermitted. if it's not, then it means that the user has taken no explicit action to permit/deny
21
- // and therefore we default to checking the permissions defined in the schema automatically.
22
- if (getPermissionState() === PERMISSION_STATE.UNPERMITTED) {
23
- throw new PermissionError(`Not permitted to access ${request.method}`);
24
- }
25
- });
26
- });
27
- }
28
-
29
- module.exports.tryExecuteJob = tryExecuteJob;
@@ -1,17 +0,0 @@
1
- const { withDatabase } = require("./database");
2
- const { withAuditContext } = require("./auditing");
3
-
4
- // tryExecuteSubscriber will create a new database connection and execute the function call.
5
- function tryExecuteSubscriber({ request, db, functionConfig }, cb) {
6
- let requiresTransaction = false;
7
- if (functionConfig?.dbTransaction !== undefined) {
8
- requiresTransaction = functionConfig.dbTransaction;
9
- }
10
- return withDatabase(db, requiresTransaction, async () => {
11
- await withAuditContext(request, async () => {
12
- return cb();
13
- });
14
- });
15
- }
16
-
17
- module.exports.tryExecuteSubscriber = tryExecuteSubscriber;
package/src/type-utils.js DELETED
@@ -1,18 +0,0 @@
1
- const { Duration } = require("./Duration");
2
-
3
- function isPlainObject(obj) {
4
- return Object.prototype.toString.call(obj) === "[object Object]";
5
- }
6
-
7
- function isRichType(obj) {
8
- if (!isPlainObject(obj)) {
9
- return false;
10
- }
11
-
12
- return obj instanceof Duration;
13
- }
14
-
15
- module.exports = {
16
- isPlainObject,
17
- isRichType,
18
- };
package/vite.config.js DELETED
@@ -1,7 +0,0 @@
1
- import { defineConfig, loadEnv } from "vite";
2
-
3
- export default ({ mode }) => {
4
- process.env = { ...process.env, ...loadEnv(mode, process.cwd(), "") };
5
-
6
- return defineConfig({});
7
- };