@tinacms/datalayer 0.0.0-f696c7d-20241104134240 → 0.0.0-f894432-20251221235528
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 +25 -46
- package/package.json +7 -22
- package/dist/index.mjs +0 -142
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(
|
|
@@ -119,7 +96,8 @@ function MakeNodeApiHandler({
|
|
|
119
96
|
const result = await databaseClient.request({
|
|
120
97
|
query,
|
|
121
98
|
variables,
|
|
122
|
-
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
user: req2?.session?.user
|
|
123
101
|
});
|
|
124
102
|
res2.statusCode = 200;
|
|
125
103
|
res2.write(JSON.stringify(result));
|
|
@@ -145,7 +123,9 @@ function MakeNodeApiHandler({
|
|
|
145
123
|
const isAuth = await isAuthorized(req, res);
|
|
146
124
|
if (isAuth.isAuthorized === false) {
|
|
147
125
|
res.statusCode = isAuth.errorCode;
|
|
148
|
-
res.write(
|
|
126
|
+
res.write(
|
|
127
|
+
JSON.stringify({ error: isAuth.errorMessage || "not found" })
|
|
128
|
+
);
|
|
149
129
|
res.end();
|
|
150
130
|
return;
|
|
151
131
|
}
|
|
@@ -154,8 +134,7 @@ function MakeNodeApiHandler({
|
|
|
154
134
|
};
|
|
155
135
|
return tinaBackendHandler;
|
|
156
136
|
}
|
|
157
|
-
|
|
158
|
-
0 && (module.exports = {
|
|
137
|
+
export {
|
|
159
138
|
AuditFileSystemBridge,
|
|
160
139
|
FilesystemBridge,
|
|
161
140
|
IsomorphicBridge,
|
|
@@ -165,4 +144,4 @@ function MakeNodeApiHandler({
|
|
|
165
144
|
createDatabase,
|
|
166
145
|
createLocalDatabase,
|
|
167
146
|
resolve
|
|
168
|
-
}
|
|
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-f894432-20251221235528",
|
|
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
|
-
"import": "./dist/index.mjs",
|
|
14
|
-
"require": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts"
|
|
16
|
-
},
|
|
17
|
-
"./dist/*": {
|
|
18
|
-
"import": "./dist/*.mjs",
|
|
19
|
-
"require": "./dist/*.js",
|
|
20
|
-
"types": "./dist/*.d.ts"
|
|
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-f894432-20251221235528"
|
|
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.7.4",
|
|
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,142 +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
|
-
user: req2?.session?.user
|
|
98
|
-
});
|
|
99
|
-
res2.statusCode = 200;
|
|
100
|
-
res2.write(JSON.stringify(result));
|
|
101
|
-
res2.end();
|
|
102
|
-
return;
|
|
103
|
-
},
|
|
104
|
-
secure: true
|
|
105
|
-
},
|
|
106
|
-
...extraRoutes || {}
|
|
107
|
-
};
|
|
108
|
-
const [action] = routes;
|
|
109
|
-
const currentRoute = allRoutes[action];
|
|
110
|
-
if (!currentRoute) {
|
|
111
|
-
res.statusCode = 404;
|
|
112
|
-
const errorMessage = `Error: ${action} not found in routes`;
|
|
113
|
-
console.error(errorMessage);
|
|
114
|
-
res.write(JSON.stringify({ error: errorMessage }));
|
|
115
|
-
res.end();
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const { handler, secure } = currentRoute;
|
|
119
|
-
if (secure) {
|
|
120
|
-
const isAuth = await isAuthorized(req, res);
|
|
121
|
-
if (isAuth.isAuthorized === false) {
|
|
122
|
-
res.statusCode = isAuth.errorCode;
|
|
123
|
-
res.write(JSON.stringify({ error: isAuth.errorMessage || "not found" }));
|
|
124
|
-
res.end();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return handler(req, res, opts);
|
|
129
|
-
};
|
|
130
|
-
return tinaBackendHandler;
|
|
131
|
-
}
|
|
132
|
-
export {
|
|
133
|
-
AuditFileSystemBridge,
|
|
134
|
-
FilesystemBridge,
|
|
135
|
-
IsomorphicBridge,
|
|
136
|
-
LocalBackendAuthProvider,
|
|
137
|
-
TinaLevelClient,
|
|
138
|
-
TinaNodeBackend,
|
|
139
|
-
createDatabase,
|
|
140
|
-
createLocalDatabase,
|
|
141
|
-
resolve
|
|
142
|
-
};
|