@holo-js/adapter-shared 0.3.15 → 0.3.17
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.mjs +1 -1
- package/dist/{chunk-NSZSPJAF.mjs → chunk-4DGYQBYZ.mjs} +8 -9
- package/dist/chunk-Q3PONPDT.mjs +25 -0
- package/dist/index.mjs +1 -1
- package/dist/next/request-context.d.ts +13 -0
- package/dist/next/request-context.mjs +8 -0
- package/dist/next/request-context.node.d.ts +1 -0
- package/dist/next/request-context.node.mjs +13 -0
- package/dist/sveltekit/request-context.d.ts +25 -0
- package/dist/sveltekit/request-context.mjs +13 -0
- package/package.json +16 -3
package/dist/build.mjs
CHANGED
|
@@ -87,35 +87,35 @@ function compileShape(node, fieldName, runtime, path = "fields") {
|
|
|
87
87
|
const nested = compileShape(property.initializer, fieldName, runtime, `${path}[${JSON.stringify(key)}]`);
|
|
88
88
|
if (!nested) return void 0;
|
|
89
89
|
fields.push(`${JSON.stringify(key)}: ${nested.fields}`);
|
|
90
|
-
schemas.push(`${JSON.stringify(key)}: ${nested.code}`);
|
|
90
|
+
schemas.push(`${JSON.stringify(key)}: ((parentExecution) => ${nested.code})(${runtime}.createExecutionNode(parentExecution, ${JSON.stringify(key)}))`);
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
93
|
const field = compileField(property.initializer, fieldName, runtime, `${path}[${JSON.stringify(key)}].definition`);
|
|
94
94
|
if (!field) return void 0;
|
|
95
95
|
const rules = field.definition.rules.map((rule) => `Object.freeze({name: ${JSON.stringify(rule.name)}, args: Object.freeze(${JSON.stringify(rule.args)})${rule.message ? `, message: ${JSON.stringify(rule.message)}` : ""}})`);
|
|
96
96
|
fields.push(`${JSON.stringify(key)}: Object.freeze({kind: 'field', definition: Object.freeze({kind: ${JSON.stringify(field.definition.kind)}, item: undefined, ${field.definition.sensitive ? "sensitive: true," : ""} rules: Object.freeze([${rules.join(",")}])})})`);
|
|
97
|
-
schemas.push(`${JSON.stringify(key)}: ${field.code}`);
|
|
97
|
+
schemas.push(`${JSON.stringify(key)}: ${runtime}.createCompiledFieldSchema(${path}[${JSON.stringify(key)}].definition, ${field.code}, ${runtime}.createExecutionNode(parentExecution, ${JSON.stringify(key)}))`);
|
|
98
98
|
}
|
|
99
|
-
return { fields: `Object.freeze({${fields.join(",")}})`, code: `${runtime}.objectAsync({${schemas.join(",")}})` };
|
|
99
|
+
return { fields: `Object.freeze({${fields.join(",")}})`, code: `${runtime}.createShapeExecutionSchema(${runtime}.objectAsync({${schemas.join(",")}}), parentExecution)` };
|
|
100
100
|
}
|
|
101
101
|
function compileBrowserValidation(source, fileName = "schema.tsx") {
|
|
102
|
-
if (!source.includes("@holo-js/
|
|
102
|
+
if (!source.includes("@holo-js/validation")) return void 0;
|
|
103
103
|
const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true);
|
|
104
104
|
const diagnostics = ts.transpileModule(source, { fileName, reportDiagnostics: true, compilerOptions: { jsx: ts.JsxEmit.Preserve } }).diagnostics;
|
|
105
105
|
if (diagnostics?.some((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error)) return void 0;
|
|
106
106
|
let fieldName;
|
|
107
|
-
const schemaNames = /* @__PURE__ */ new
|
|
107
|
+
const schemaNames = /* @__PURE__ */ new Set();
|
|
108
108
|
for (const statement of file.statements) {
|
|
109
109
|
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
110
110
|
const packageName = statement.moduleSpecifier.text;
|
|
111
|
-
if (packageName !== "@holo-js/
|
|
111
|
+
if (packageName !== "@holo-js/validation") continue;
|
|
112
112
|
const bindings = statement.importClause?.namedBindings;
|
|
113
113
|
if (!bindings || !ts.isNamedImports(bindings) || statement.importClause?.isTypeOnly) continue;
|
|
114
114
|
for (const binding of bindings.elements) {
|
|
115
115
|
if (binding.isTypeOnly) continue;
|
|
116
116
|
const name = binding.propertyName?.text ?? binding.name.text;
|
|
117
117
|
if (name === "field") fieldName = binding.name.text;
|
|
118
|
-
if (name === "schema" || name === "defineSchema") schemaNames.
|
|
118
|
+
if (name === "schema" || name === "defineSchema") schemaNames.add(binding.name.text);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
if (!fieldName || schemaNames.size === 0) return void 0;
|
|
@@ -131,8 +131,7 @@ function compileBrowserValidation(source, fileName = "schema.tsx") {
|
|
|
131
131
|
if (!shape || !ts.isObjectLiteralExpression(shape)) continue;
|
|
132
132
|
const compiled = compileShape(shape, fieldName, runtime);
|
|
133
133
|
if (!compiled) continue;
|
|
134
|
-
const
|
|
135
|
-
const code = `(() => { const fields = ${compiled.fields}; const compiled = ${compiled.code}; return Object.freeze({kind: 'schema', ${mode} fields, '~standard': {version: 1, vendor: 'holo-js', validate: ${runtime}.createSchemaStandardValidate(fields, () => compiled), types: undefined}}) })()`;
|
|
134
|
+
const code = `(() => { const fields = ${compiled.fields}; return Object.freeze({kind: 'schema', fields, '~standard': {version: 1, vendor: 'holo-js', validate: ${runtime}.createSchemaStandardValidate(fields, parentExecution => ${compiled.code}), types: undefined}}) })()`;
|
|
136
135
|
replacements.push({ start: call.getStart(file), end: call.end, code });
|
|
137
136
|
}
|
|
138
137
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/next/request-store.ts
|
|
2
|
+
function getNextRequestStore(storage) {
|
|
3
|
+
const globals = globalThis;
|
|
4
|
+
if (globals.__holoNextRequestStore) return globals.__holoNextRequestStore;
|
|
5
|
+
const NativeStorage = globals.AsyncLocalStorage ?? storage;
|
|
6
|
+
if (!NativeStorage) {
|
|
7
|
+
throw new Error("Next request context requires native AsyncLocalStorage");
|
|
8
|
+
}
|
|
9
|
+
globals.__holoNextRequestStore = new NativeStorage();
|
|
10
|
+
return globals.__holoNextRequestStore;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/next/request-context.ts
|
|
14
|
+
function getCurrentNextRequest() {
|
|
15
|
+
return getNextRequestStore().getStore();
|
|
16
|
+
}
|
|
17
|
+
function runWithNextRequest(request, callback) {
|
|
18
|
+
return getNextRequestStore().run(request, callback);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
getNextRequestStore,
|
|
23
|
+
getCurrentNextRequest,
|
|
24
|
+
runWithNextRequest
|
|
25
|
+
};
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
createRealtimeClientDefinitionModule,
|
|
9
9
|
createRealtimeClientDefinitionTransform,
|
|
10
10
|
stripRealtimeServerHandlers
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-4DGYQBYZ.mjs";
|
|
12
12
|
export {
|
|
13
13
|
compileBrowserValidation,
|
|
14
14
|
createRealtimeClientDefinitionModule,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type NextRequestLike = {
|
|
2
|
+
readonly cookies: {
|
|
3
|
+
get(name: string): {
|
|
4
|
+
readonly value: string;
|
|
5
|
+
} | undefined;
|
|
6
|
+
};
|
|
7
|
+
readonly headers: Headers;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
declare function getCurrentNextRequest(): NextRequestLike | undefined;
|
|
11
|
+
declare function runWithNextRequest<TValue>(request: NextRequestLike, callback: () => TValue): TValue;
|
|
12
|
+
|
|
13
|
+
export { type NextRequestLike, getCurrentNextRequest, runWithNextRequest };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NextRequestLike, getCurrentNextRequest, runWithNextRequest } from './request-context.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentNextRequest,
|
|
3
|
+
getNextRequestStore,
|
|
4
|
+
runWithNextRequest
|
|
5
|
+
} from "../chunk-Q3PONPDT.mjs";
|
|
6
|
+
|
|
7
|
+
// src/next/request-context.node.ts
|
|
8
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
9
|
+
getNextRequestStore(AsyncLocalStorage);
|
|
10
|
+
export {
|
|
11
|
+
getCurrentNextRequest,
|
|
12
|
+
runWithNextRequest
|
|
13
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type SvelteKitRequestEvent = {
|
|
2
|
+
readonly url?: URL;
|
|
3
|
+
readonly cookies: {
|
|
4
|
+
get(name: string): string | undefined;
|
|
5
|
+
set(name: string, value: string, options: SvelteKitCookieOptions): void;
|
|
6
|
+
};
|
|
7
|
+
readonly request: {
|
|
8
|
+
readonly method?: string;
|
|
9
|
+
readonly headers: Headers;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type SvelteKitCookieOptions = {
|
|
13
|
+
path: string;
|
|
14
|
+
domain?: string;
|
|
15
|
+
maxAge?: number;
|
|
16
|
+
expires?: Date;
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
httpOnly?: boolean;
|
|
19
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
20
|
+
partitioned?: boolean;
|
|
21
|
+
};
|
|
22
|
+
declare function getCurrentSvelteKitRequestEvent(): SvelteKitRequestEvent | undefined;
|
|
23
|
+
declare function runWithSvelteKitRequestEvent<TValue>(event: SvelteKitRequestEvent, callback: () => TValue): TValue;
|
|
24
|
+
|
|
25
|
+
export { type SvelteKitRequestEvent, getCurrentSvelteKitRequestEvent, runWithSvelteKitRequestEvent };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/sveltekit/request-context.ts
|
|
2
|
+
var runtimeGlobal = globalThis;
|
|
3
|
+
function getCurrentSvelteKitRequestEvent() {
|
|
4
|
+
return runtimeGlobal.__holoSvelteKitRequestEventStore?.getStore();
|
|
5
|
+
}
|
|
6
|
+
function runWithSvelteKitRequestEvent(event, callback) {
|
|
7
|
+
runtimeGlobal.__holoSvelteKitRequestEventStore ??= new (process.getBuiltinModule("node:async_hooks")).AsyncLocalStorage();
|
|
8
|
+
return runtimeGlobal.__holoSvelteKitRequestEventStore.run(event, callback);
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
getCurrentSvelteKitRequestEvent,
|
|
12
|
+
runWithSvelteKitRequestEvent
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/adapter-shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"description": "Holo-JS Framework - shared framework adapter infrastructure",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,19 @@
|
|
|
19
19
|
"types": "./dist/build.d.ts",
|
|
20
20
|
"import": "./dist/build.mjs",
|
|
21
21
|
"default": "./dist/build.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./next/request-context": {
|
|
24
|
+
"types": "./dist/next/request-context.d.ts",
|
|
25
|
+
"browser": "./dist/next/request-context.mjs",
|
|
26
|
+
"edge-light": "./dist/next/request-context.mjs",
|
|
27
|
+
"node": "./dist/next/request-context.node.mjs",
|
|
28
|
+
"import": "./dist/next/request-context.mjs",
|
|
29
|
+
"default": "./dist/next/request-context.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./sveltekit/request-context": {
|
|
32
|
+
"types": "./dist/sveltekit/request-context.d.ts",
|
|
33
|
+
"import": "./dist/sveltekit/request-context.mjs",
|
|
34
|
+
"default": "./dist/sveltekit/request-context.mjs"
|
|
22
35
|
}
|
|
23
36
|
},
|
|
24
37
|
"main": "./dist/index.mjs",
|
|
@@ -33,7 +46,7 @@
|
|
|
33
46
|
"test": "vitest --run"
|
|
34
47
|
},
|
|
35
48
|
"dependencies": {
|
|
36
|
-
"@holo-js/kernel": "^0.3.
|
|
49
|
+
"@holo-js/kernel": "^0.3.17",
|
|
37
50
|
"typescript": "^5.7.2"
|
|
38
51
|
},
|
|
39
52
|
"devDependencies": {
|
|
@@ -41,6 +54,6 @@
|
|
|
41
54
|
"vitest": "^4.1.5"
|
|
42
55
|
},
|
|
43
56
|
"engines": {
|
|
44
|
-
"node": "
|
|
57
|
+
"node": "^22.12.0 || ^24.0.0 || ^26.0.0"
|
|
45
58
|
}
|
|
46
59
|
}
|