@tinacms/datalayer 1.4.3 → 2.0.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/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
- var index_exports = {};
21
- __export(index_exports, {
22
- AuditFileSystemBridge: () => import_graphql.AuditFileSystemBridge,
23
- FilesystemBridge: () => import_graphql.FilesystemBridge,
24
- IsomorphicBridge: () => import_graphql.IsomorphicBridge,
25
- LocalBackendAuthProvider: () => LocalBackendAuthProvider,
26
- TinaLevelClient: () => import_graphql.TinaLevelClient,
27
- TinaNodeBackend: () => TinaNodeBackend,
28
- createDatabase: () => import_graphql.createDatabase,
29
- createLocalDatabase: () => import_graphql.createLocalDatabase,
30
- resolve: () => import_graphql.resolve
31
- });
32
- module.exports = __toCommonJS(index_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 = () => ({
@@ -157,8 +134,7 @@ function MakeNodeApiHandler({
157
134
  };
158
135
  return tinaBackendHandler;
159
136
  }
160
- // Annotate the CommonJS export names for ESM import in node:
161
- 0 && (module.exports = {
137
+ export {
162
138
  AuditFileSystemBridge,
163
139
  FilesystemBridge,
164
140
  IsomorphicBridge,
@@ -168,4 +144,4 @@ function MakeNodeApiHandler({
168
144
  createDatabase,
169
145
  createLocalDatabase,
170
146
  resolve
171
- });
147
+ };
package/package.json CHANGED
@@ -1,25 +1,13 @@
1
1
  {
2
2
  "name": "@tinacms/datalayer",
3
- "version": "1.4.3",
3
+ "type": "module",
4
+ "version": "2.0.1",
4
5
  "main": "dist/index.js",
5
- "module": "dist/index.mjs",
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": "1.6.3"
22
+ "@tinacms/graphql": "2.0.1"
35
23
  },
36
24
  "publishConfig": {
37
25
  "registry": "https://registry.npmjs.org"
@@ -52,7 +40,7 @@
52
40
  "jest-file-snapshot": "^0.5.0",
53
41
  "jest-matcher-utils": "^29.7.0",
54
42
  "typescript": "^5.7.3",
55
- "@tinacms/scripts": "1.4.1"
43
+ "@tinacms/scripts": "1.4.2"
56
44
  },
57
45
  "scripts": {
58
46
  "types": "pnpm tsc",
package/dist/index.mjs DELETED
@@ -1,147 +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(
49
- "Please name your next api route [...routes] not [route]"
50
- );
51
- }
52
- if (!routes?.length) {
53
- console.error(
54
- `A request was made to ${opts.basePath} but no route was found`
55
- );
56
- res.statusCode = 404;
57
- res.write(JSON.stringify({ error: "not found" }));
58
- res.end();
59
- return;
60
- }
61
- const allRoutes = {
62
- gql: {
63
- handler: async (req2, res2, _opts) => {
64
- if (req2.method !== "POST") {
65
- res2.statusCode = 405;
66
- res2.write(
67
- JSON.stringify({
68
- error: "Method not allowed. Only POST requests are supported by /gql"
69
- })
70
- );
71
- res2.end();
72
- return;
73
- }
74
- if (!req2.body) {
75
- console.error(
76
- "Please make sure that you have a body parser set up for your server and req.body is defined"
77
- );
78
- res2.statusCode = 400;
79
- res2.write(JSON.stringify({ error: "no body" }));
80
- res2.end();
81
- return;
82
- }
83
- if (!req2.body.query) {
84
- res2.statusCode = 400;
85
- res2.write(JSON.stringify({ error: "no query" }));
86
- res2.end();
87
- return;
88
- }
89
- if (!req2.body.variables) {
90
- res2.statusCode = 400;
91
- res2.write(JSON.stringify({ error: "no variables" }));
92
- res2.end();
93
- return;
94
- }
95
- const { query, variables } = req2.body;
96
- const result = await databaseClient.request({
97
- query,
98
- variables,
99
- // @ts-ignore
100
- user: req2?.session?.user
101
- });
102
- res2.statusCode = 200;
103
- res2.write(JSON.stringify(result));
104
- res2.end();
105
- return;
106
- },
107
- secure: true
108
- },
109
- ...extraRoutes || {}
110
- };
111
- const [action] = routes;
112
- const currentRoute = allRoutes[action];
113
- if (!currentRoute) {
114
- res.statusCode = 404;
115
- const errorMessage = `Error: ${action} not found in routes`;
116
- console.error(errorMessage);
117
- res.write(JSON.stringify({ error: errorMessage }));
118
- res.end();
119
- return;
120
- }
121
- const { handler, secure } = currentRoute;
122
- if (secure) {
123
- const isAuth = await isAuthorized(req, res);
124
- if (isAuth.isAuthorized === false) {
125
- res.statusCode = isAuth.errorCode;
126
- res.write(
127
- JSON.stringify({ error: isAuth.errorMessage || "not found" })
128
- );
129
- res.end();
130
- return;
131
- }
132
- }
133
- return handler(req, res, opts);
134
- };
135
- return tinaBackendHandler;
136
- }
137
- export {
138
- AuditFileSystemBridge,
139
- FilesystemBridge,
140
- IsomorphicBridge,
141
- LocalBackendAuthProvider,
142
- TinaLevelClient,
143
- TinaNodeBackend,
144
- createDatabase,
145
- createLocalDatabase,
146
- resolve
147
- };