@fragno-dev/core 0.1.11 → 0.2.0
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/.turbo/turbo-build.log +50 -42
- package/CHANGELOG.md +51 -0
- package/dist/api/api.d.ts +19 -1
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js.map +1 -1
- package/dist/api/fragment-definition-builder.d.ts +17 -7
- package/dist/api/fragment-definition-builder.d.ts.map +1 -1
- package/dist/api/fragment-definition-builder.js +3 -2
- package/dist/api/fragment-definition-builder.js.map +1 -1
- package/dist/api/fragment-instantiator.d.ts +23 -16
- package/dist/api/fragment-instantiator.d.ts.map +1 -1
- package/dist/api/fragment-instantiator.js +163 -19
- package/dist/api/fragment-instantiator.js.map +1 -1
- package/dist/api/request-input-context.d.ts +57 -1
- package/dist/api/request-input-context.d.ts.map +1 -1
- package/dist/api/request-input-context.js +67 -0
- package/dist/api/request-input-context.js.map +1 -1
- package/dist/api/request-middleware.d.ts +1 -1
- package/dist/api/request-middleware.d.ts.map +1 -1
- package/dist/api/request-middleware.js.map +1 -1
- package/dist/api/route.d.ts +7 -7
- package/dist/api/route.d.ts.map +1 -1
- package/dist/api/route.js.map +1 -1
- package/dist/client/client.d.ts +4 -3
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +103 -7
- package/dist/client/client.js.map +1 -1
- package/dist/client/vue.d.ts +7 -3
- package/dist/client/vue.d.ts.map +1 -1
- package/dist/client/vue.js +16 -1
- package/dist/client/vue.js.map +1 -1
- package/dist/internal/trace-context.d.ts +23 -0
- package/dist/internal/trace-context.d.ts.map +1 -0
- package/dist/internal/trace-context.js +14 -0
- package/dist/internal/trace-context.js.map +1 -0
- package/dist/mod-client.d.ts +3 -17
- package/dist/mod-client.d.ts.map +1 -1
- package/dist/mod-client.js +20 -10
- package/dist/mod-client.js.map +1 -1
- package/dist/mod.d.ts +3 -2
- package/dist/mod.js +2 -1
- package/dist/runtime.d.ts +15 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +33 -0
- package/dist/runtime.js.map +1 -0
- package/dist/test/test.d.ts +2 -2
- package/dist/test/test.d.ts.map +1 -1
- package/dist/test/test.js.map +1 -1
- package/package.json +23 -17
- package/src/api/api.ts +22 -0
- package/src/api/fragment-definition-builder.ts +36 -17
- package/src/api/fragment-instantiator.test.ts +286 -0
- package/src/api/fragment-instantiator.ts +338 -31
- package/src/api/internal/path-runtime.test.ts +7 -0
- package/src/api/request-input-context.test.ts +152 -0
- package/src/api/request-input-context.ts +85 -0
- package/src/api/request-middleware.test.ts +47 -1
- package/src/api/request-middleware.ts +1 -1
- package/src/api/route.ts +7 -2
- package/src/client/client.test.ts +195 -0
- package/src/client/client.ts +185 -10
- package/src/client/vue.test.ts +253 -3
- package/src/client/vue.ts +44 -1
- package/src/internal/trace-context.ts +35 -0
- package/src/mod-client.ts +51 -7
- package/src/mod.ts +6 -1
- package/src/runtime.ts +48 -0
- package/src/test/test.ts +13 -4
- package/tsdown.config.ts +1 -0
package/src/mod-client.ts
CHANGED
|
@@ -35,7 +35,7 @@ export function defineFragment(_name: string) {
|
|
|
35
35
|
name: _name,
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const stubMethods = {
|
|
39
39
|
withDependencies: () => stub,
|
|
40
40
|
providesBaseService: () => stub,
|
|
41
41
|
providesService: () => stub,
|
|
@@ -48,7 +48,21 @@ export function defineFragment(_name: string) {
|
|
|
48
48
|
withLinkedFragment: () => stub,
|
|
49
49
|
extend: () => stub,
|
|
50
50
|
build: () => definitionStub,
|
|
51
|
+
// From fragno-db
|
|
52
|
+
provideHooks: () => stub,
|
|
51
53
|
};
|
|
54
|
+
|
|
55
|
+
// Wrap with Proxy to handle any additional methods (e.g. from extend())
|
|
56
|
+
const stub: object = new Proxy(stubMethods, {
|
|
57
|
+
get(target, prop) {
|
|
58
|
+
if (prop in target) {
|
|
59
|
+
return target[prop as keyof typeof target];
|
|
60
|
+
}
|
|
61
|
+
// Return a function that returns the stub for method chaining
|
|
62
|
+
return () => stub;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
52
66
|
return stub;
|
|
53
67
|
}
|
|
54
68
|
|
|
@@ -58,7 +72,7 @@ export { FragmentDefinitionBuilder } from "./api/fragment-definition-builder";
|
|
|
58
72
|
// Stub implementation for instantiate
|
|
59
73
|
// This is stripped by unplugin-fragno in browser builds
|
|
60
74
|
export function instantiate(_definition: unknown) {
|
|
61
|
-
const
|
|
75
|
+
const fragmentStubMethods = {
|
|
62
76
|
[instantiatedFragmentFakeSymbol]: instantiatedFragmentFakeSymbol,
|
|
63
77
|
name: "",
|
|
64
78
|
routes: [],
|
|
@@ -71,10 +85,7 @@ export function instantiate(_definition: unknown) {
|
|
|
71
85
|
linkedFragments: {},
|
|
72
86
|
};
|
|
73
87
|
},
|
|
74
|
-
withMiddleware: () =>
|
|
75
|
-
// throw new Error("withMiddleware is not supported in browser builds");
|
|
76
|
-
return fragmentStub;
|
|
77
|
-
},
|
|
88
|
+
withMiddleware: () => fragmentStub,
|
|
78
89
|
inContext: <T>(callback: () => T) => callback(),
|
|
79
90
|
handlersFor: () => ({}),
|
|
80
91
|
handler: async () => new Response(),
|
|
@@ -82,7 +93,21 @@ export function instantiate(_definition: unknown) {
|
|
|
82
93
|
callRouteRaw: async () => new Response(),
|
|
83
94
|
};
|
|
84
95
|
|
|
85
|
-
|
|
96
|
+
// Wrap with Proxy to handle any additional methods
|
|
97
|
+
const fragmentStub: IFragnoInstantiatedFragment = new Proxy(
|
|
98
|
+
fragmentStubMethods as IFragnoInstantiatedFragment,
|
|
99
|
+
{
|
|
100
|
+
get(target, prop) {
|
|
101
|
+
if (prop in target) {
|
|
102
|
+
return target[prop as keyof typeof target];
|
|
103
|
+
}
|
|
104
|
+
// Return a function that returns the stub for method chaining
|
|
105
|
+
return () => fragmentStub;
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const builderStubMethods = {
|
|
86
111
|
withConfig: () => builderStub,
|
|
87
112
|
withRoutes: () => builderStub,
|
|
88
113
|
withOptions: () => builderStub,
|
|
@@ -94,6 +119,20 @@ export function instantiate(_definition: unknown) {
|
|
|
94
119
|
options: undefined,
|
|
95
120
|
};
|
|
96
121
|
|
|
122
|
+
// Wrap with Proxy to handle any additional methods
|
|
123
|
+
const builderStub: IFragmentInstantiationBuilder = new Proxy(
|
|
124
|
+
builderStubMethods as IFragmentInstantiationBuilder,
|
|
125
|
+
{
|
|
126
|
+
get(target, prop) {
|
|
127
|
+
if (prop in target) {
|
|
128
|
+
return target[prop as keyof typeof target];
|
|
129
|
+
}
|
|
130
|
+
// Return a function that returns the stub for method chaining
|
|
131
|
+
return () => builderStub;
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
|
|
97
136
|
return builderStub;
|
|
98
137
|
}
|
|
99
138
|
|
|
@@ -102,6 +141,11 @@ export function instantiate(_definition: unknown) {
|
|
|
102
141
|
// ============================================================================
|
|
103
142
|
export type { FragnoPublicConfig } from "./api/shared-types";
|
|
104
143
|
|
|
144
|
+
// ============================================================================
|
|
145
|
+
// Runtime
|
|
146
|
+
// ============================================================================
|
|
147
|
+
export { defaultFragnoRuntime, type FragnoRuntime } from "./runtime";
|
|
148
|
+
|
|
105
149
|
// ============================================================================
|
|
106
150
|
// Route Definition
|
|
107
151
|
// ============================================================================
|
package/src/mod.ts
CHANGED
|
@@ -25,6 +25,11 @@ export {
|
|
|
25
25
|
// ============================================================================
|
|
26
26
|
export type { FragnoPublicConfig } from "./api/shared-types";
|
|
27
27
|
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Runtime
|
|
30
|
+
// ============================================================================
|
|
31
|
+
export { defaultFragnoRuntime, type FragnoRuntime } from "./runtime";
|
|
32
|
+
|
|
28
33
|
// ============================================================================
|
|
29
34
|
// Route Definition
|
|
30
35
|
// ============================================================================
|
|
@@ -35,4 +40,4 @@ export {
|
|
|
35
40
|
type RouteFactoryContext,
|
|
36
41
|
} from "./api/route";
|
|
37
42
|
|
|
38
|
-
export { type FragnoRouteConfig, type RequestThisContext } from "./api/api";
|
|
43
|
+
export { type FragnoRouteConfig, type RequestThisContext, type RouteContentType } from "./api/api";
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createId } from "@paralleldrive/cuid2";
|
|
2
|
+
|
|
3
|
+
export type FragnoRuntime = {
|
|
4
|
+
time: {
|
|
5
|
+
now: () => Date;
|
|
6
|
+
};
|
|
7
|
+
random: {
|
|
8
|
+
float: () => number;
|
|
9
|
+
uuid: () => string;
|
|
10
|
+
cuid: () => string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const fallbackUuid = () => {
|
|
15
|
+
const bytes = new Uint8Array(16);
|
|
16
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
17
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// RFC 4122 variant + version 4
|
|
21
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
22
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
23
|
+
|
|
24
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
25
|
+
return [
|
|
26
|
+
hex.slice(0, 4).join(""),
|
|
27
|
+
hex.slice(4, 6).join(""),
|
|
28
|
+
hex.slice(6, 8).join(""),
|
|
29
|
+
hex.slice(8, 10).join(""),
|
|
30
|
+
hex.slice(10, 16).join(""),
|
|
31
|
+
].join("-");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const defaultUuid = () => {
|
|
35
|
+
const cryptoApi = globalThis.crypto;
|
|
36
|
+
return cryptoApi?.randomUUID ? cryptoApi.randomUUID() : fallbackUuid();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const defaultFragnoRuntime: FragnoRuntime = {
|
|
40
|
+
time: {
|
|
41
|
+
now: () => new Date(),
|
|
42
|
+
},
|
|
43
|
+
random: {
|
|
44
|
+
float: () => Math.random(),
|
|
45
|
+
uuid: () => defaultUuid(),
|
|
46
|
+
cuid: () => createId(),
|
|
47
|
+
},
|
|
48
|
+
};
|
package/src/test/test.ts
CHANGED
|
@@ -6,7 +6,12 @@ import {
|
|
|
6
6
|
type FragmentDefinition,
|
|
7
7
|
type ServiceConstructorFn,
|
|
8
8
|
} from "../api/fragment-definition-builder";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
instantiateFragment,
|
|
11
|
+
type AnyFragnoInstantiatedFragment,
|
|
12
|
+
type FragnoInstantiatedFragment,
|
|
13
|
+
type RoutesWithInternal,
|
|
14
|
+
} from "../api/fragment-instantiator";
|
|
10
15
|
import type { BoundServices } from "../api/bind-services";
|
|
11
16
|
|
|
12
17
|
// Re-export for convenience
|
|
@@ -200,6 +205,7 @@ export function createFragmentForTest<
|
|
|
200
205
|
THandlerThisContext extends RequestThisContext,
|
|
201
206
|
TRequestStorage,
|
|
202
207
|
const TRoutesOrFactories extends readonly AnyRouteOrFactory[],
|
|
208
|
+
TLinkedFragments extends Record<string, AnyFragnoInstantiatedFragment> = {},
|
|
203
209
|
>(
|
|
204
210
|
definition: FragmentDefinition<
|
|
205
211
|
TConfig,
|
|
@@ -211,17 +217,20 @@ export function createFragmentForTest<
|
|
|
211
217
|
TPrivateServices,
|
|
212
218
|
TServiceThisContext,
|
|
213
219
|
THandlerThisContext,
|
|
214
|
-
TRequestStorage
|
|
220
|
+
TRequestStorage,
|
|
221
|
+
TLinkedFragments
|
|
215
222
|
>,
|
|
216
223
|
routesOrFactories: TRoutesOrFactories,
|
|
217
224
|
options: CreateFragmentForTestOptions<TConfig, TOptions, TServiceDependencies>,
|
|
218
225
|
): FragnoInstantiatedFragment<
|
|
219
|
-
FlattenRouteFactories<TRoutesOrFactories>,
|
|
226
|
+
RoutesWithInternal<FlattenRouteFactories<TRoutesOrFactories>, TLinkedFragments>,
|
|
220
227
|
TDeps,
|
|
221
228
|
BoundServices<TBaseServices & TServices>,
|
|
222
229
|
TServiceThisContext,
|
|
223
230
|
THandlerThisContext,
|
|
224
|
-
TRequestStorage
|
|
231
|
+
TRequestStorage,
|
|
232
|
+
TOptions,
|
|
233
|
+
TLinkedFragments
|
|
225
234
|
> {
|
|
226
235
|
const { config, options: fragmentOptions = {} as TOptions, serviceImplementations } = options;
|
|
227
236
|
|