@tinacms/datalayer 0.0.0-942e18f-20250102010803 → 0.0.0-96fe3b4-20251217041317
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/dist/index.js +24 -46
- package/package.json +7 -22
- package/dist/index.mjs +0 -143
package/dist/index.js
CHANGED
|
@@ -1,36 +1,13 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
1
|
// src/index.ts
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
AuditFileSystemBridge
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
createLocalDatabase: () => import_graphql.createLocalDatabase,
|
|
30
|
-
resolve: () => import_graphql.resolve
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(src_exports);
|
|
33
|
-
var import_graphql = require("@tinacms/graphql");
|
|
2
|
+
import {
|
|
3
|
+
FilesystemBridge,
|
|
4
|
+
AuditFileSystemBridge,
|
|
5
|
+
IsomorphicBridge,
|
|
6
|
+
TinaLevelClient,
|
|
7
|
+
resolve,
|
|
8
|
+
createDatabase,
|
|
9
|
+
createLocalDatabase
|
|
10
|
+
} from "@tinacms/graphql";
|
|
34
11
|
|
|
35
12
|
// src/backend/index.ts
|
|
36
13
|
var LocalBackendAuthProvider = () => ({
|
|
@@ -42,10 +19,10 @@ function TinaNodeBackend({
|
|
|
42
19
|
options
|
|
43
20
|
}) {
|
|
44
21
|
const { initialize, isAuthorized, extraRoutes } = authProvider;
|
|
45
|
-
initialize
|
|
22
|
+
initialize?.().catch((e) => {
|
|
46
23
|
console.error(e);
|
|
47
24
|
});
|
|
48
|
-
const basePath =
|
|
25
|
+
const basePath = options?.basePath ? `/${options.basePath.replace(/^\/?/, "").replace(/\/?$/, "")}/` : "/api/tina/";
|
|
49
26
|
const opts = {
|
|
50
27
|
basePath
|
|
51
28
|
};
|
|
@@ -64,14 +41,15 @@ function MakeNodeApiHandler({
|
|
|
64
41
|
opts
|
|
65
42
|
}) {
|
|
66
43
|
const tinaBackendHandler = async (req, res) => {
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const routes = (_d = (_c = url.pathname) == null ? void 0 : _c.replace(opts.basePath, "")) == null ? void 0 : _d.split("/");
|
|
44
|
+
const path = req.url?.startsWith("/") ? req.url.slice(1) : req.url;
|
|
45
|
+
const url = new URL(path, `http://${req.headers?.host || "localhost"}`);
|
|
46
|
+
const routes = url.pathname?.replace(opts.basePath, "")?.split("/");
|
|
71
47
|
if (typeof routes === "string") {
|
|
72
|
-
throw new Error(
|
|
48
|
+
throw new Error(
|
|
49
|
+
"Please name your next api route [...routes] not [route]"
|
|
50
|
+
);
|
|
73
51
|
}
|
|
74
|
-
if (!
|
|
52
|
+
if (!routes?.length) {
|
|
75
53
|
console.error(
|
|
76
54
|
`A request was made to ${opts.basePath} but no route was found`
|
|
77
55
|
);
|
|
@@ -83,7 +61,6 @@ function MakeNodeApiHandler({
|
|
|
83
61
|
const allRoutes = {
|
|
84
62
|
gql: {
|
|
85
63
|
handler: async (req2, res2, _opts) => {
|
|
86
|
-
var _a2;
|
|
87
64
|
if (req2.method !== "POST") {
|
|
88
65
|
res2.statusCode = 405;
|
|
89
66
|
res2.write(
|
|
@@ -120,7 +97,7 @@ function MakeNodeApiHandler({
|
|
|
120
97
|
query,
|
|
121
98
|
variables,
|
|
122
99
|
// @ts-ignore
|
|
123
|
-
user:
|
|
100
|
+
user: req2?.session?.user
|
|
124
101
|
});
|
|
125
102
|
res2.statusCode = 200;
|
|
126
103
|
res2.write(JSON.stringify(result));
|
|
@@ -146,7 +123,9 @@ function MakeNodeApiHandler({
|
|
|
146
123
|
const isAuth = await isAuthorized(req, res);
|
|
147
124
|
if (isAuth.isAuthorized === false) {
|
|
148
125
|
res.statusCode = isAuth.errorCode;
|
|
149
|
-
res.write(
|
|
126
|
+
res.write(
|
|
127
|
+
JSON.stringify({ error: isAuth.errorMessage || "not found" })
|
|
128
|
+
);
|
|
150
129
|
res.end();
|
|
151
130
|
return;
|
|
152
131
|
}
|
|
@@ -155,8 +134,7 @@ function MakeNodeApiHandler({
|
|
|
155
134
|
};
|
|
156
135
|
return tinaBackendHandler;
|
|
157
136
|
}
|
|
158
|
-
|
|
159
|
-
0 && (module.exports = {
|
|
137
|
+
export {
|
|
160
138
|
AuditFileSystemBridge,
|
|
161
139
|
FilesystemBridge,
|
|
162
140
|
IsomorphicBridge,
|
|
@@ -166,4 +144,4 @@ function MakeNodeApiHandler({
|
|
|
166
144
|
createDatabase,
|
|
167
145
|
createLocalDatabase,
|
|
168
146
|
resolve
|
|
169
|
-
}
|
|
147
|
+
};
|
package/package.json
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/datalayer",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0-96fe3b4-20251217041317",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
|
-
"
|
|
6
|
-
"typings": "dist/index",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"package.json",
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.mjs",
|
|
15
|
-
"require": "./dist/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./dist/*": {
|
|
18
|
-
"types": "./dist/*.d.ts",
|
|
19
|
-
"import": "./dist/*.mjs",
|
|
20
|
-
"require": "./dist/*.js"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
11
|
"license": "SEE LICENSE IN LICENSE",
|
|
24
12
|
"buildConfig": {
|
|
25
13
|
"entryPoints": [
|
|
@@ -31,7 +19,7 @@
|
|
|
31
19
|
]
|
|
32
20
|
},
|
|
33
21
|
"dependencies": {
|
|
34
|
-
"@tinacms/graphql": "0.0.0-
|
|
22
|
+
"@tinacms/graphql": "0.0.0-96fe3b4-20251217041317"
|
|
35
23
|
},
|
|
36
24
|
"publishConfig": {
|
|
37
25
|
"registry": "https://registry.npmjs.org"
|
|
@@ -45,17 +33,14 @@
|
|
|
45
33
|
"@types/jest": "^27.5.2",
|
|
46
34
|
"@types/js-yaml": "^3.12.10",
|
|
47
35
|
"@types/level": "^6.0.3",
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/lodash.upperfirst": "^4.3.9",
|
|
50
|
-
"@types/node": "^22.9.0",
|
|
36
|
+
"@types/node": "^22.13.1",
|
|
51
37
|
"@types/normalize-path": "^3.0.2",
|
|
52
|
-
"@types/yup": "^0.29.14",
|
|
53
38
|
"jest": "^29.7.0",
|
|
54
39
|
"jest-diff": "^29.7.0",
|
|
55
40
|
"jest-file-snapshot": "^0.5.0",
|
|
56
41
|
"jest-matcher-utils": "^29.7.0",
|
|
57
|
-
"typescript": "^5.
|
|
58
|
-
"@tinacms/scripts": "1.
|
|
42
|
+
"typescript": "^5.7.3",
|
|
43
|
+
"@tinacms/scripts": "1.4.2"
|
|
59
44
|
},
|
|
60
45
|
"scripts": {
|
|
61
46
|
"types": "pnpm tsc",
|
package/dist/index.mjs
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
FilesystemBridge,
|
|
4
|
-
AuditFileSystemBridge,
|
|
5
|
-
IsomorphicBridge,
|
|
6
|
-
TinaLevelClient,
|
|
7
|
-
resolve,
|
|
8
|
-
createDatabase,
|
|
9
|
-
createLocalDatabase
|
|
10
|
-
} from "@tinacms/graphql";
|
|
11
|
-
|
|
12
|
-
// src/backend/index.ts
|
|
13
|
-
var LocalBackendAuthProvider = () => ({
|
|
14
|
-
isAuthorized: async () => ({ isAuthorized: true })
|
|
15
|
-
});
|
|
16
|
-
function TinaNodeBackend({
|
|
17
|
-
authProvider,
|
|
18
|
-
databaseClient,
|
|
19
|
-
options
|
|
20
|
-
}) {
|
|
21
|
-
const { initialize, isAuthorized, extraRoutes } = authProvider;
|
|
22
|
-
initialize?.().catch((e) => {
|
|
23
|
-
console.error(e);
|
|
24
|
-
});
|
|
25
|
-
const basePath = options?.basePath ? `/${options.basePath.replace(/^\/?/, "").replace(/\/?$/, "")}/` : "/api/tina/";
|
|
26
|
-
const opts = {
|
|
27
|
-
basePath
|
|
28
|
-
};
|
|
29
|
-
const handler = MakeNodeApiHandler({
|
|
30
|
-
isAuthorized,
|
|
31
|
-
extraRoutes,
|
|
32
|
-
databaseClient,
|
|
33
|
-
opts
|
|
34
|
-
});
|
|
35
|
-
return handler;
|
|
36
|
-
}
|
|
37
|
-
function MakeNodeApiHandler({
|
|
38
|
-
isAuthorized,
|
|
39
|
-
extraRoutes,
|
|
40
|
-
databaseClient,
|
|
41
|
-
opts
|
|
42
|
-
}) {
|
|
43
|
-
const tinaBackendHandler = async (req, res) => {
|
|
44
|
-
const path = req.url?.startsWith("/") ? req.url.slice(1) : req.url;
|
|
45
|
-
const url = new URL(path, `http://${req.headers?.host || "localhost"}`);
|
|
46
|
-
const routes = url.pathname?.replace(opts.basePath, "")?.split("/");
|
|
47
|
-
if (typeof routes === "string") {
|
|
48
|
-
throw new Error("Please name your next api route [...routes] not [route]");
|
|
49
|
-
}
|
|
50
|
-
if (!routes?.length) {
|
|
51
|
-
console.error(
|
|
52
|
-
`A request was made to ${opts.basePath} but no route was found`
|
|
53
|
-
);
|
|
54
|
-
res.statusCode = 404;
|
|
55
|
-
res.write(JSON.stringify({ error: "not found" }));
|
|
56
|
-
res.end();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const allRoutes = {
|
|
60
|
-
gql: {
|
|
61
|
-
handler: async (req2, res2, _opts) => {
|
|
62
|
-
if (req2.method !== "POST") {
|
|
63
|
-
res2.statusCode = 405;
|
|
64
|
-
res2.write(
|
|
65
|
-
JSON.stringify({
|
|
66
|
-
error: "Method not allowed. Only POST requests are supported by /gql"
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
res2.end();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (!req2.body) {
|
|
73
|
-
console.error(
|
|
74
|
-
"Please make sure that you have a body parser set up for your server and req.body is defined"
|
|
75
|
-
);
|
|
76
|
-
res2.statusCode = 400;
|
|
77
|
-
res2.write(JSON.stringify({ error: "no body" }));
|
|
78
|
-
res2.end();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!req2.body.query) {
|
|
82
|
-
res2.statusCode = 400;
|
|
83
|
-
res2.write(JSON.stringify({ error: "no query" }));
|
|
84
|
-
res2.end();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (!req2.body.variables) {
|
|
88
|
-
res2.statusCode = 400;
|
|
89
|
-
res2.write(JSON.stringify({ error: "no variables" }));
|
|
90
|
-
res2.end();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const { query, variables } = req2.body;
|
|
94
|
-
const result = await databaseClient.request({
|
|
95
|
-
query,
|
|
96
|
-
variables,
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
user: req2?.session?.user
|
|
99
|
-
});
|
|
100
|
-
res2.statusCode = 200;
|
|
101
|
-
res2.write(JSON.stringify(result));
|
|
102
|
-
res2.end();
|
|
103
|
-
return;
|
|
104
|
-
},
|
|
105
|
-
secure: true
|
|
106
|
-
},
|
|
107
|
-
...extraRoutes || {}
|
|
108
|
-
};
|
|
109
|
-
const [action] = routes;
|
|
110
|
-
const currentRoute = allRoutes[action];
|
|
111
|
-
if (!currentRoute) {
|
|
112
|
-
res.statusCode = 404;
|
|
113
|
-
const errorMessage = `Error: ${action} not found in routes`;
|
|
114
|
-
console.error(errorMessage);
|
|
115
|
-
res.write(JSON.stringify({ error: errorMessage }));
|
|
116
|
-
res.end();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const { handler, secure } = currentRoute;
|
|
120
|
-
if (secure) {
|
|
121
|
-
const isAuth = await isAuthorized(req, res);
|
|
122
|
-
if (isAuth.isAuthorized === false) {
|
|
123
|
-
res.statusCode = isAuth.errorCode;
|
|
124
|
-
res.write(JSON.stringify({ error: isAuth.errorMessage || "not found" }));
|
|
125
|
-
res.end();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return handler(req, res, opts);
|
|
130
|
-
};
|
|
131
|
-
return tinaBackendHandler;
|
|
132
|
-
}
|
|
133
|
-
export {
|
|
134
|
-
AuditFileSystemBridge,
|
|
135
|
-
FilesystemBridge,
|
|
136
|
-
IsomorphicBridge,
|
|
137
|
-
LocalBackendAuthProvider,
|
|
138
|
-
TinaLevelClient,
|
|
139
|
-
TinaNodeBackend,
|
|
140
|
-
createDatabase,
|
|
141
|
-
createLocalDatabase,
|
|
142
|
-
resolve
|
|
143
|
-
};
|