@cedarjs/internal 4.2.1-next.0 → 4.2.1-next.269
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/build/api.d.ts +1 -0
- package/dist/build/api.d.ts.map +1 -1
- package/dist/build/api.js +74 -7
- package/dist/build/esbuild-plugin-cedar-context-wrapping.d.ts +4 -0
- package/dist/build/esbuild-plugin-cedar-context-wrapping.d.ts.map +1 -0
- package/dist/build/esbuild-plugin-cedar-context-wrapping.js +35 -0
- package/dist/cjs/build/api.d.ts +1 -0
- package/dist/cjs/build/api.d.ts.map +1 -1
- package/dist/cjs/build/api.js +75 -7
- package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.d.ts +4 -0
- package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.d.ts.map +1 -0
- package/dist/cjs/build/esbuild-plugin-cedar-context-wrapping.js +59 -0
- package/dist/cjs/generate/gqlormSchema.d.ts +2 -0
- package/dist/cjs/generate/gqlormSchema.d.ts.map +1 -1
- package/dist/cjs/generate/gqlormSchema.js +325 -1
- package/dist/cjs/generate/plugins/rw-typescript-resolvers/visitor.d.ts.map +1 -1
- package/dist/cjs/generate/typeDefinitions.js +5 -8
- package/dist/cjs/validateSchema.js +2 -2
- package/dist/generate/gqlormSchema.d.ts +2 -0
- package/dist/generate/gqlormSchema.d.ts.map +1 -1
- package/dist/generate/gqlormSchema.js +325 -1
- package/dist/generate/plugins/rw-typescript-resolvers/visitor.d.ts.map +1 -1
- package/dist/generate/typeDefinitions.js +5 -8
- package/dist/validateSchema.js +2 -2
- package/package.json +20 -14
package/dist/build/api.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare const buildApi: () => Promise<import("esbuild").BuildResult<Build
|
|
|
3
3
|
export declare const rebuildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
4
4
|
export declare const cleanApiBuild: () => Promise<void>;
|
|
5
5
|
export declare const buildApiWithVite: () => Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
|
|
6
|
+
export declare function fixSourceMaps(distDir: string, srcDir: string): Promise<void>;
|
|
6
7
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/build/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AAiBtE,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AA8FD,eAAO,MAAM,gBAAgB,iHAqD5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/build/api.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "@cedarjs/babel-config";
|
|
9
9
|
import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
|
|
10
10
|
import { findApiFiles } from "../files.js";
|
|
11
|
+
import { applyContextWrapping } from "./esbuild-plugin-cedar-context-wrapping.js";
|
|
11
12
|
let BUILD_CTX = null;
|
|
12
13
|
const buildApi = async () => {
|
|
13
14
|
BUILD_CTX?.dispose();
|
|
@@ -19,7 +20,10 @@ const rebuildApi = async () => {
|
|
|
19
20
|
if (!BUILD_CTX) {
|
|
20
21
|
BUILD_CTX = await context(getEsbuildOptions(apiFiles));
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
const result = await BUILD_CTX.rebuild();
|
|
24
|
+
const cedarPaths = getPaths();
|
|
25
|
+
await fixSourceMaps(cedarPaths.api.dist, cedarPaths.api.src);
|
|
26
|
+
return result;
|
|
23
27
|
};
|
|
24
28
|
const cleanApiBuild = async () => {
|
|
25
29
|
const cedarPaths = getPaths();
|
|
@@ -30,7 +34,9 @@ const runCedarBabelTransformsPlugin = {
|
|
|
30
34
|
setup(build2) {
|
|
31
35
|
const cedarConfig = getConfig();
|
|
32
36
|
build2.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
|
|
37
|
+
const fileContents = await fs.promises.readFile(args.path, "utf-8");
|
|
33
38
|
const transformedCode = await transformWithBabel(
|
|
39
|
+
fileContents,
|
|
34
40
|
args.path,
|
|
35
41
|
getApiSideBabelPlugins({
|
|
36
42
|
openTelemetry: cedarConfig.experimental.opentelemetry.enabled && cedarConfig.experimental.opentelemetry.wrapApi,
|
|
@@ -38,8 +44,14 @@ const runCedarBabelTransformsPlugin = {
|
|
|
38
44
|
})
|
|
39
45
|
);
|
|
40
46
|
if (transformedCode?.code) {
|
|
47
|
+
const functionsDir = normalizePath(
|
|
48
|
+
path.join(getPaths().api.src, "functions")
|
|
49
|
+
);
|
|
50
|
+
const code = normalizePath(args.path).startsWith(functionsDir + "/") ? applyContextWrapping(transformedCode.code, {
|
|
51
|
+
projectIsEsm: projectSideIsEsm("api")
|
|
52
|
+
}) ?? transformedCode.code : transformedCode.code;
|
|
41
53
|
return {
|
|
42
|
-
contents:
|
|
54
|
+
contents: code,
|
|
43
55
|
loader: "js"
|
|
44
56
|
};
|
|
45
57
|
}
|
|
@@ -52,7 +64,8 @@ function createCedarViteApiPlugin() {
|
|
|
52
64
|
const isEsm = projectSideIsEsm("api");
|
|
53
65
|
return {
|
|
54
66
|
name: "cedar-vite-api-babel-transform",
|
|
55
|
-
|
|
67
|
+
enforce: "pre",
|
|
68
|
+
async transform(code, id) {
|
|
56
69
|
if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
|
|
57
70
|
return null;
|
|
58
71
|
}
|
|
@@ -64,15 +77,23 @@ function createCedarViteApiPlugin() {
|
|
|
64
77
|
return null;
|
|
65
78
|
}
|
|
66
79
|
const transformedCode = await transformWithBabel(
|
|
80
|
+
code,
|
|
67
81
|
id,
|
|
68
82
|
getApiSideBabelPlugins({
|
|
69
83
|
openTelemetry: cedarConfig.experimental.opentelemetry.enabled && cedarConfig.experimental.opentelemetry.wrapApi,
|
|
70
84
|
projectIsEsm: isEsm
|
|
71
|
-
})
|
|
85
|
+
}),
|
|
86
|
+
true
|
|
72
87
|
);
|
|
73
88
|
if (transformedCode?.code) {
|
|
89
|
+
const functionsDir = normalizePath(
|
|
90
|
+
path.join(cedarPaths.api.src, "functions")
|
|
91
|
+
);
|
|
92
|
+
const code2 = normalizePath(id).startsWith(functionsDir + "/") ? applyContextWrapping(transformedCode.code, {
|
|
93
|
+
projectIsEsm: isEsm
|
|
94
|
+
}) ?? transformedCode.code : transformedCode.code;
|
|
74
95
|
return {
|
|
75
|
-
code:
|
|
96
|
+
code: code2,
|
|
76
97
|
map: transformedCode.map ?? null
|
|
77
98
|
};
|
|
78
99
|
}
|
|
@@ -103,7 +124,11 @@ const buildApiWithVite = async () => {
|
|
|
103
124
|
format,
|
|
104
125
|
preserveModules: true,
|
|
105
126
|
preserveModulesRoot: cedarPaths.api.src,
|
|
106
|
-
entryFileNames: "[name].js"
|
|
127
|
+
entryFileNames: "[name].js",
|
|
128
|
+
// Directives (and other entry modules) intentionally use both named
|
|
129
|
+
// and default exports (e.g. `export const schema` + `export default`).
|
|
130
|
+
// Tell Rollup to expect this so it doesn't warn about mixed exports.
|
|
131
|
+
exports: "named"
|
|
107
132
|
},
|
|
108
133
|
external: (id) => {
|
|
109
134
|
if (id.startsWith("node:")) {
|
|
@@ -120,8 +145,49 @@ const buildApiWithVite = async () => {
|
|
|
120
145
|
});
|
|
121
146
|
};
|
|
122
147
|
const transpileApi = async (files) => {
|
|
123
|
-
|
|
148
|
+
const result = await build(getEsbuildOptions(files));
|
|
149
|
+
const cedarPaths = getPaths();
|
|
150
|
+
await fixSourceMaps(cedarPaths.api.dist, cedarPaths.api.src);
|
|
151
|
+
return result;
|
|
124
152
|
};
|
|
153
|
+
async function fixSourceMaps(distDir, srcDir) {
|
|
154
|
+
let entries;
|
|
155
|
+
try {
|
|
156
|
+
entries = await fs.promises.readdir(distDir, {
|
|
157
|
+
recursive: true,
|
|
158
|
+
withFileTypes: true
|
|
159
|
+
});
|
|
160
|
+
} catch {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const mapFiles = entries.filter((e) => e.isFile() && e.name.endsWith(".js.map")).map((e) => path.join(e.parentPath ?? e.path, e.name));
|
|
164
|
+
await Promise.all(
|
|
165
|
+
mapFiles.map(async (mapFile) => {
|
|
166
|
+
try {
|
|
167
|
+
const raw = await fs.promises.readFile(mapFile, "utf8");
|
|
168
|
+
const map = JSON.parse(raw);
|
|
169
|
+
if (!Array.isArray(map.sources) || map.sources.length === 0) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const jsFile = mapFile.slice(0, -4);
|
|
173
|
+
const baseName = path.relative(distDir, jsFile).replace(/\.js$/, "");
|
|
174
|
+
const srcFile = [".ts", ".tsx", ".jsx", ".js"].map((ext) => path.join(srcDir, baseName + ext)).find((f) => fs.existsSync(f));
|
|
175
|
+
if (!srcFile) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const correctRelPath = normalizePath(
|
|
179
|
+
path.relative(path.dirname(mapFile), srcFile)
|
|
180
|
+
);
|
|
181
|
+
if (map.sources[0] === correctRelPath) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
map.sources = [correctRelPath];
|
|
185
|
+
await fs.promises.writeFile(mapFile, JSON.stringify(map), "utf8");
|
|
186
|
+
} catch {
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
}
|
|
125
191
|
function getEsbuildOptions(files) {
|
|
126
192
|
const cedarPaths = getPaths();
|
|
127
193
|
const format = projectSideIsEsm("api") ? "esm" : "cjs";
|
|
@@ -145,5 +211,6 @@ export {
|
|
|
145
211
|
buildApi,
|
|
146
212
|
buildApiWithVite,
|
|
147
213
|
cleanApiBuild,
|
|
214
|
+
fixSourceMaps,
|
|
148
215
|
rebuildApi
|
|
149
216
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAOA,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CA0Cf"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function applyContextWrapping(code, { projectIsEsm = false } = {}) {
|
|
2
|
+
const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
|
|
3
|
+
const handlerMatch = handlerRe.exec(code);
|
|
4
|
+
if (!handlerMatch) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
|
|
8
|
+
const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
|
|
9
|
+
const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
|
|
10
|
+
const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
|
|
11
|
+
`;
|
|
12
|
+
const handlerStart = handlerMatch.index;
|
|
13
|
+
const before = code.slice(0, handlerStart);
|
|
14
|
+
const after = code.slice(handlerStart);
|
|
15
|
+
const renamed = after.replace(handlerRe, "const __rw_handler =");
|
|
16
|
+
const wrappedHandler = `
|
|
17
|
+
export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
|
|
18
|
+
// The store will be undefined if no context isolation has been performed yet
|
|
19
|
+
const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
|
|
20
|
+
if (__rw_contextStore === undefined) {
|
|
21
|
+
return __rw_getAsyncStoreInstance().run(
|
|
22
|
+
new Map(),
|
|
23
|
+
__rw_handler,
|
|
24
|
+
__rw_event,
|
|
25
|
+
__rw__context
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
return __rw_handler(__rw_event, __rw__context)
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
return before + importStatement + renamed + wrappedHandler;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
applyContextWrapping
|
|
35
|
+
};
|
package/dist/cjs/build/api.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare const buildApi: () => Promise<import("esbuild").BuildResult<Build
|
|
|
3
3
|
export declare const rebuildApi: () => Promise<import("esbuild").BuildResult<BuildOptions>>;
|
|
4
4
|
export declare const cleanApiBuild: () => Promise<void>;
|
|
5
5
|
export declare const buildApiWithVite: () => Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
|
|
6
|
+
export declare function fixSourceMaps(distDir: string, srcDir: string): Promise<void>;
|
|
6
7
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AAiBtE,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AA8FD,eAAO,MAAM,gBAAgB,iHAqD5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/cjs/build/api.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(api_exports, {
|
|
|
31
31
|
buildApi: () => buildApi,
|
|
32
32
|
buildApiWithVite: () => buildApiWithVite,
|
|
33
33
|
cleanApiBuild: () => cleanApiBuild,
|
|
34
|
+
fixSourceMaps: () => fixSourceMaps,
|
|
34
35
|
rebuildApi: () => rebuildApi
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(api_exports);
|
|
@@ -41,6 +42,7 @@ var import_vite = require("vite");
|
|
|
41
42
|
var import_babel_config = require("@cedarjs/babel-config");
|
|
42
43
|
var import_project_config = require("@cedarjs/project-config");
|
|
43
44
|
var import_files = require("../files.js");
|
|
45
|
+
var import_esbuild_plugin_cedar_context_wrapping = require("./esbuild-plugin-cedar-context-wrapping.js");
|
|
44
46
|
let BUILD_CTX = null;
|
|
45
47
|
const buildApi = async () => {
|
|
46
48
|
BUILD_CTX?.dispose();
|
|
@@ -52,7 +54,10 @@ const rebuildApi = async () => {
|
|
|
52
54
|
if (!BUILD_CTX) {
|
|
53
55
|
BUILD_CTX = await (0, import_esbuild.context)(getEsbuildOptions(apiFiles));
|
|
54
56
|
}
|
|
55
|
-
|
|
57
|
+
const result = await BUILD_CTX.rebuild();
|
|
58
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
59
|
+
await fixSourceMaps(cedarPaths.api.dist, cedarPaths.api.src);
|
|
60
|
+
return result;
|
|
56
61
|
};
|
|
57
62
|
const cleanApiBuild = async () => {
|
|
58
63
|
const cedarPaths = (0, import_project_config.getPaths)();
|
|
@@ -63,7 +68,9 @@ const runCedarBabelTransformsPlugin = {
|
|
|
63
68
|
setup(build2) {
|
|
64
69
|
const cedarConfig = (0, import_project_config.getConfig)();
|
|
65
70
|
build2.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
|
|
71
|
+
const fileContents = await import_node_fs.default.promises.readFile(args.path, "utf-8");
|
|
66
72
|
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
73
|
+
fileContents,
|
|
67
74
|
args.path,
|
|
68
75
|
(0, import_babel_config.getApiSideBabelPlugins)({
|
|
69
76
|
openTelemetry: cedarConfig.experimental.opentelemetry.enabled && cedarConfig.experimental.opentelemetry.wrapApi,
|
|
@@ -71,8 +78,14 @@ const runCedarBabelTransformsPlugin = {
|
|
|
71
78
|
})
|
|
72
79
|
);
|
|
73
80
|
if (transformedCode?.code) {
|
|
81
|
+
const functionsDir = (0, import_vite.normalizePath)(
|
|
82
|
+
import_node_path.default.join((0, import_project_config.getPaths)().api.src, "functions")
|
|
83
|
+
);
|
|
84
|
+
const code = (0, import_vite.normalizePath)(args.path).startsWith(functionsDir + "/") ? (0, import_esbuild_plugin_cedar_context_wrapping.applyContextWrapping)(transformedCode.code, {
|
|
85
|
+
projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
|
|
86
|
+
}) ?? transformedCode.code : transformedCode.code;
|
|
74
87
|
return {
|
|
75
|
-
contents:
|
|
88
|
+
contents: code,
|
|
76
89
|
loader: "js"
|
|
77
90
|
};
|
|
78
91
|
}
|
|
@@ -85,7 +98,8 @@ function createCedarViteApiPlugin() {
|
|
|
85
98
|
const isEsm = (0, import_project_config.projectSideIsEsm)("api");
|
|
86
99
|
return {
|
|
87
100
|
name: "cedar-vite-api-babel-transform",
|
|
88
|
-
|
|
101
|
+
enforce: "pre",
|
|
102
|
+
async transform(code, id) {
|
|
89
103
|
if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
|
|
90
104
|
return null;
|
|
91
105
|
}
|
|
@@ -97,15 +111,23 @@ function createCedarViteApiPlugin() {
|
|
|
97
111
|
return null;
|
|
98
112
|
}
|
|
99
113
|
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
114
|
+
code,
|
|
100
115
|
id,
|
|
101
116
|
(0, import_babel_config.getApiSideBabelPlugins)({
|
|
102
117
|
openTelemetry: cedarConfig.experimental.opentelemetry.enabled && cedarConfig.experimental.opentelemetry.wrapApi,
|
|
103
118
|
projectIsEsm: isEsm
|
|
104
|
-
})
|
|
119
|
+
}),
|
|
120
|
+
true
|
|
105
121
|
);
|
|
106
122
|
if (transformedCode?.code) {
|
|
123
|
+
const functionsDir = (0, import_vite.normalizePath)(
|
|
124
|
+
import_node_path.default.join(cedarPaths.api.src, "functions")
|
|
125
|
+
);
|
|
126
|
+
const code2 = (0, import_vite.normalizePath)(id).startsWith(functionsDir + "/") ? (0, import_esbuild_plugin_cedar_context_wrapping.applyContextWrapping)(transformedCode.code, {
|
|
127
|
+
projectIsEsm: isEsm
|
|
128
|
+
}) ?? transformedCode.code : transformedCode.code;
|
|
107
129
|
return {
|
|
108
|
-
code:
|
|
130
|
+
code: code2,
|
|
109
131
|
map: transformedCode.map ?? null
|
|
110
132
|
};
|
|
111
133
|
}
|
|
@@ -136,7 +158,11 @@ const buildApiWithVite = async () => {
|
|
|
136
158
|
format,
|
|
137
159
|
preserveModules: true,
|
|
138
160
|
preserveModulesRoot: cedarPaths.api.src,
|
|
139
|
-
entryFileNames: "[name].js"
|
|
161
|
+
entryFileNames: "[name].js",
|
|
162
|
+
// Directives (and other entry modules) intentionally use both named
|
|
163
|
+
// and default exports (e.g. `export const schema` + `export default`).
|
|
164
|
+
// Tell Rollup to expect this so it doesn't warn about mixed exports.
|
|
165
|
+
exports: "named"
|
|
140
166
|
},
|
|
141
167
|
external: (id) => {
|
|
142
168
|
if (id.startsWith("node:")) {
|
|
@@ -153,8 +179,49 @@ const buildApiWithVite = async () => {
|
|
|
153
179
|
});
|
|
154
180
|
};
|
|
155
181
|
const transpileApi = async (files) => {
|
|
156
|
-
|
|
182
|
+
const result = await (0, import_esbuild.build)(getEsbuildOptions(files));
|
|
183
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
184
|
+
await fixSourceMaps(cedarPaths.api.dist, cedarPaths.api.src);
|
|
185
|
+
return result;
|
|
157
186
|
};
|
|
187
|
+
async function fixSourceMaps(distDir, srcDir) {
|
|
188
|
+
let entries;
|
|
189
|
+
try {
|
|
190
|
+
entries = await import_node_fs.default.promises.readdir(distDir, {
|
|
191
|
+
recursive: true,
|
|
192
|
+
withFileTypes: true
|
|
193
|
+
});
|
|
194
|
+
} catch {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const mapFiles = entries.filter((e) => e.isFile() && e.name.endsWith(".js.map")).map((e) => import_node_path.default.join(e.parentPath ?? e.path, e.name));
|
|
198
|
+
await Promise.all(
|
|
199
|
+
mapFiles.map(async (mapFile) => {
|
|
200
|
+
try {
|
|
201
|
+
const raw = await import_node_fs.default.promises.readFile(mapFile, "utf8");
|
|
202
|
+
const map = JSON.parse(raw);
|
|
203
|
+
if (!Array.isArray(map.sources) || map.sources.length === 0) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const jsFile = mapFile.slice(0, -4);
|
|
207
|
+
const baseName = import_node_path.default.relative(distDir, jsFile).replace(/\.js$/, "");
|
|
208
|
+
const srcFile = [".ts", ".tsx", ".jsx", ".js"].map((ext) => import_node_path.default.join(srcDir, baseName + ext)).find((f) => import_node_fs.default.existsSync(f));
|
|
209
|
+
if (!srcFile) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const correctRelPath = (0, import_vite.normalizePath)(
|
|
213
|
+
import_node_path.default.relative(import_node_path.default.dirname(mapFile), srcFile)
|
|
214
|
+
);
|
|
215
|
+
if (map.sources[0] === correctRelPath) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
map.sources = [correctRelPath];
|
|
219
|
+
await import_node_fs.default.promises.writeFile(mapFile, JSON.stringify(map), "utf8");
|
|
220
|
+
} catch {
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
}
|
|
158
225
|
function getEsbuildOptions(files) {
|
|
159
226
|
const cedarPaths = (0, import_project_config.getPaths)();
|
|
160
227
|
const format = (0, import_project_config.projectSideIsEsm)("api") ? "esm" : "cjs";
|
|
@@ -179,5 +246,6 @@ function getEsbuildOptions(files) {
|
|
|
179
246
|
buildApi,
|
|
180
247
|
buildApiWithVite,
|
|
181
248
|
cleanApiBuild,
|
|
249
|
+
fixSourceMaps,
|
|
182
250
|
rebuildApi
|
|
183
251
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../../src/build/esbuild-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAOA,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CA0Cf"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var esbuild_plugin_cedar_context_wrapping_exports = {};
|
|
20
|
+
__export(esbuild_plugin_cedar_context_wrapping_exports, {
|
|
21
|
+
applyContextWrapping: () => applyContextWrapping
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(esbuild_plugin_cedar_context_wrapping_exports);
|
|
24
|
+
function applyContextWrapping(code, { projectIsEsm = false } = {}) {
|
|
25
|
+
const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
|
|
26
|
+
const handlerMatch = handlerRe.exec(code);
|
|
27
|
+
if (!handlerMatch) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
|
|
31
|
+
const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
|
|
32
|
+
const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
|
|
33
|
+
const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
|
|
34
|
+
`;
|
|
35
|
+
const handlerStart = handlerMatch.index;
|
|
36
|
+
const before = code.slice(0, handlerStart);
|
|
37
|
+
const after = code.slice(handlerStart);
|
|
38
|
+
const renamed = after.replace(handlerRe, "const __rw_handler =");
|
|
39
|
+
const wrappedHandler = `
|
|
40
|
+
export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
|
|
41
|
+
// The store will be undefined if no context isolation has been performed yet
|
|
42
|
+
const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
|
|
43
|
+
if (__rw_contextStore === undefined) {
|
|
44
|
+
return __rw_getAsyncStoreInstance().run(
|
|
45
|
+
new Map(),
|
|
46
|
+
__rw_handler,
|
|
47
|
+
__rw_event,
|
|
48
|
+
__rw__context
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
return __rw_handler(__rw_event, __rw__context)
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
return before + importStatement + renamed + wrappedHandler;
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
applyContextWrapping
|
|
59
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AA8BzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE3C,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAMD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"gqlormSchema.d.ts","sourceRoot":"","sources":["../../../src/generate/gqlormSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,cAAc,CAAA;AA8BzC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE3C,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAMD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,OAAO,CAAA;IACb,eAAe,EAAE,OAAO,CAAA;IACxB,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,gBAAgB,EAAE,CAAA;IAC1B,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAAA;CACtC;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,mBAAmB,EAAE,MAAM,CAAA;IAC3B,2BAA2B,EAAE,MAAM,CAAA;IACnC,qBAAqB,EAAE,OAAO,CAAA;CAC/B;AA6DD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMvE;AAoGD,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAClB,iBAAiB,EAAE,CAiDrB;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,iBAAiB,EAAE,GAC1B,MAAM,CA2CR;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAkDjE;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,EAAE,CA6D7E;AAkBD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CA6BvE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,EAAE,EAC1B,MAAM,GAAE,mBAAmD,GAC1D,MAAM,CA+rBR;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC;IACvD,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAC9C,CAAC,CAkID"}
|