zitejs 0.10.1-device.0 → 0.10.2
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/cjs/auth/actions.js +0 -2
- package/dist/cjs/auth/client.js +0 -5
- package/dist/cjs/auth/useAuth.test.js +0 -1
- package/dist/cjs/caller/index.js +16 -5
- package/dist/cjs/check/index.js +10 -4
- package/dist/cjs/start/build/entries.d.ts +5 -0
- package/dist/cjs/start/build/entries.js +37 -12
- package/dist/cjs/start/build/roleIds.d.ts +11 -0
- package/dist/cjs/start/build/roleIds.js +59 -0
- package/dist/cjs/start/describe/schema.d.ts +574 -0
- package/dist/cjs/start/describe/schema.js +178 -0
- package/dist/cjs/start/protocol.d.ts +7 -0
- package/dist/cjs/start/protocol.js +27 -3
- package/dist/cjs/start/serve/authHookNames.d.ts +3 -0
- package/dist/cjs/start/serve/authHookNames.js +13 -0
- package/dist/cjs/vite/index.js +0 -41
- package/dist/cjs/vite/index.test.js +0 -36
- package/dist/esm/auth/actions.js +0 -2
- package/dist/esm/auth/client.js +0 -5
- package/dist/esm/auth/useAuth.test.js +0 -1
- package/dist/esm/caller/index.js +15 -4
- package/dist/esm/check/index.js +10 -4
- package/dist/esm/start/build/entries.d.ts +5 -0
- package/dist/esm/start/build/entries.js +37 -13
- package/dist/esm/start/build/roleIds.d.ts +11 -0
- package/dist/esm/start/build/roleIds.js +54 -0
- package/dist/esm/start/build/vite.js +0 -4
- package/dist/esm/start/classicOnly.js +3 -3
- package/dist/esm/start/describe/schema.d.ts +574 -0
- package/dist/esm/start/describe/schema.js +175 -0
- package/dist/esm/start/describe/schema.test-d.d.ts +1 -0
- package/dist/esm/start/describe/schema.test-d.js +23 -0
- package/dist/esm/start/index.d.ts +1 -1
- package/dist/esm/start/protocol.d.ts +7 -0
- package/dist/esm/start/protocol.js +17 -2
- package/dist/esm/start/roles.d.ts +10 -2
- package/dist/esm/start/serve/authHookNames.d.ts +3 -0
- package/dist/esm/start/serve/authHookNames.js +9 -0
- package/dist/esm/start/serve/authHooks.d.ts +2 -4
- package/dist/esm/start/serve/authHooks.js +2 -8
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/vite/index.js +0 -41
- package/dist/esm/vite/index.test.js +0 -36
- package/package.json +5 -13
- package/tsconfig/start.json +40 -0
- package/dist/cjs/internal/browserMode.d.ts +0 -2
- package/dist/cjs/internal/browserMode.js +0 -18
- package/dist/cjs/internal/deviceCache.d.ts +0 -11
- package/dist/cjs/internal/deviceCache.js +0 -29
- package/dist/cjs/query/deviceCache.d.ts +0 -14
- package/dist/cjs/query/deviceCache.js +0 -304
- package/dist/cjs/query/index.d.ts +0 -19
- package/dist/cjs/query/index.js +0 -369
- package/dist/esm/internal/browserMode.d.ts +0 -2
- package/dist/esm/internal/browserMode.js +0 -15
- package/dist/esm/internal/deviceCache.d.ts +0 -11
- package/dist/esm/internal/deviceCache.js +0 -24
- package/dist/esm/query/deviceCache.d.ts +0 -14
- package/dist/esm/query/deviceCache.js +0 -301
- package/dist/esm/query/index.d.ts +0 -19
- package/dist/esm/query/index.js +0 -366
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Describe's answer as zod, for the platform to check a build's description with before it reads one: the shape of
|
|
2
|
+
// `Description`, nothing of the platform's limits. Imports only zod and the auth hook names, so
|
|
3
|
+
// zitejs/start/protocol stays light; schema.test-d.ts holds it to the type.
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { AUTH_HOOK_NAMES } from '../serve/authHookNames.js';
|
|
6
|
+
export const describedAccessSchema = z.object({
|
|
7
|
+
kind: z.enum(['signedIn', 'anyone', 'webhook', 'none']),
|
|
8
|
+
roles: z.array(z.string()),
|
|
9
|
+
paused: z.literal(true).optional(),
|
|
10
|
+
});
|
|
11
|
+
export const describedFunctionSchema = z.object({
|
|
12
|
+
id: z.string(),
|
|
13
|
+
name: z.string().optional(),
|
|
14
|
+
file: z.string().optional(),
|
|
15
|
+
method: z.string().optional(),
|
|
16
|
+
description: z.string().optional(),
|
|
17
|
+
access: describedAccessSchema,
|
|
18
|
+
/** The validator's JSON Schema, `{ unrepresentable: true }` or `{ opaque: true }`. */
|
|
19
|
+
input: z.unknown().optional(),
|
|
20
|
+
problems: z.array(z.string()),
|
|
21
|
+
});
|
|
22
|
+
export const describedRouteSchema = z.object({
|
|
23
|
+
path: z.string(),
|
|
24
|
+
file: z.string().optional(),
|
|
25
|
+
description: z.string().optional(),
|
|
26
|
+
methods: z.record(z.string(), describedAccessSchema),
|
|
27
|
+
problems: z.array(z.string()),
|
|
28
|
+
});
|
|
29
|
+
export const describedPageSchema = z.object({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
path: z.string(),
|
|
32
|
+
file: z.string().optional(),
|
|
33
|
+
});
|
|
34
|
+
const dayOfWeek = z.enum(['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']);
|
|
35
|
+
const activeWindow = z.object({
|
|
36
|
+
hoursRange: z.object({ from: z.string(), to: z.string() }).optional(),
|
|
37
|
+
daysOfWeek: z.array(dayOfWeek).optional(),
|
|
38
|
+
});
|
|
39
|
+
/** `ZiteSchedule`, as an automation declares it. */
|
|
40
|
+
export const describedScheduleSchema = z.discriminatedUnion('scheduleType', [
|
|
41
|
+
z.object({
|
|
42
|
+
scheduleType: z.literal('recurring'),
|
|
43
|
+
schedule: z.discriminatedUnion('frequency', [
|
|
44
|
+
z.object({
|
|
45
|
+
frequency: z.literal('minutely'),
|
|
46
|
+
interval: z.number(),
|
|
47
|
+
activeWindow: activeWindow.optional(),
|
|
48
|
+
}),
|
|
49
|
+
z.object({
|
|
50
|
+
frequency: z.literal('hourly'),
|
|
51
|
+
interval: z.number(),
|
|
52
|
+
minute: z.number().optional(),
|
|
53
|
+
activeWindow: activeWindow.optional(),
|
|
54
|
+
}),
|
|
55
|
+
z.object({
|
|
56
|
+
frequency: z.literal('daily'),
|
|
57
|
+
interval: z.number(),
|
|
58
|
+
times: z.array(z.string()),
|
|
59
|
+
}),
|
|
60
|
+
z.object({
|
|
61
|
+
frequency: z.literal('weekly'),
|
|
62
|
+
interval: z.number(),
|
|
63
|
+
daysOfWeek: z.array(dayOfWeek),
|
|
64
|
+
times: z.array(z.string()),
|
|
65
|
+
}),
|
|
66
|
+
z.object({
|
|
67
|
+
frequency: z.literal('monthly'),
|
|
68
|
+
interval: z.literal(1),
|
|
69
|
+
monthlyDay: z.discriminatedUnion('type', [
|
|
70
|
+
z.object({
|
|
71
|
+
type: z.literal('dayOfMonth'),
|
|
72
|
+
day: z.union([z.number(), z.literal('last')]),
|
|
73
|
+
}),
|
|
74
|
+
z.object({
|
|
75
|
+
type: z.literal('weekdayOccurrence'),
|
|
76
|
+
weekday: dayOfWeek,
|
|
77
|
+
occurrence: z.union([z.literal([1, 2, 3, 4]), z.literal('last')]),
|
|
78
|
+
}),
|
|
79
|
+
]),
|
|
80
|
+
times: z.array(z.string()),
|
|
81
|
+
}),
|
|
82
|
+
]),
|
|
83
|
+
endPolicy: z
|
|
84
|
+
.discriminatedUnion('type', [
|
|
85
|
+
z.object({ type: z.literal('never') }),
|
|
86
|
+
z.object({ type: z.literal('onDate'), endAt: z.string() }),
|
|
87
|
+
z.object({
|
|
88
|
+
type: z.literal('afterOccurrences'),
|
|
89
|
+
occurrences: z.number(),
|
|
90
|
+
}),
|
|
91
|
+
])
|
|
92
|
+
.optional(),
|
|
93
|
+
overlapPolicy: z.enum(['skip', 'allow']).optional(),
|
|
94
|
+
timezone: z.string(),
|
|
95
|
+
paused: z.boolean().optional(),
|
|
96
|
+
}),
|
|
97
|
+
z.object({
|
|
98
|
+
scheduleType: z.literal('oneTime'),
|
|
99
|
+
fireAt: z.string(),
|
|
100
|
+
timezone: z.string(),
|
|
101
|
+
paused: z.boolean().optional(),
|
|
102
|
+
}),
|
|
103
|
+
]);
|
|
104
|
+
const absent = z.never().optional();
|
|
105
|
+
const shown = { label: z.string().optional(), paused: z.boolean().optional() };
|
|
106
|
+
/**
|
|
107
|
+
* `ZiteTrigger`, as an automation declares it, without a provider trigger's `subscribe` and `unsubscribe`. Database
|
|
108
|
+
* and form triggers are in it: describe reports one it refuses.
|
|
109
|
+
*/
|
|
110
|
+
export const describedTriggerSchema = z.union([
|
|
111
|
+
z.object({
|
|
112
|
+
integration: z.string(),
|
|
113
|
+
...shown,
|
|
114
|
+
every: absent,
|
|
115
|
+
events: absent,
|
|
116
|
+
table: absent,
|
|
117
|
+
form: absent,
|
|
118
|
+
}),
|
|
119
|
+
z.object({
|
|
120
|
+
integration: z.string(),
|
|
121
|
+
events: z.array(z.string()),
|
|
122
|
+
...shown,
|
|
123
|
+
every: absent,
|
|
124
|
+
table: absent,
|
|
125
|
+
form: absent,
|
|
126
|
+
}),
|
|
127
|
+
z.object({
|
|
128
|
+
every: z.string(),
|
|
129
|
+
integration: z.string().optional(),
|
|
130
|
+
...shown,
|
|
131
|
+
events: absent,
|
|
132
|
+
table: absent,
|
|
133
|
+
form: absent,
|
|
134
|
+
}),
|
|
135
|
+
z.object({
|
|
136
|
+
table: z.string(),
|
|
137
|
+
on: z.array(z.enum(['created', 'updated', 'deleted'])),
|
|
138
|
+
fields: z.array(z.string()).optional(),
|
|
139
|
+
...shown,
|
|
140
|
+
integration: absent,
|
|
141
|
+
every: absent,
|
|
142
|
+
events: absent,
|
|
143
|
+
form: absent,
|
|
144
|
+
}),
|
|
145
|
+
z.object({
|
|
146
|
+
form: z.string(),
|
|
147
|
+
on: z.array(z.literal('submitted')),
|
|
148
|
+
...shown,
|
|
149
|
+
integration: absent,
|
|
150
|
+
every: absent,
|
|
151
|
+
events: absent,
|
|
152
|
+
table: absent,
|
|
153
|
+
}),
|
|
154
|
+
]);
|
|
155
|
+
export const describedWorkflowSchema = z.object({
|
|
156
|
+
id: z.string(),
|
|
157
|
+
file: z.string(),
|
|
158
|
+
description: z.string().optional(),
|
|
159
|
+
schedule: describedScheduleSchema.optional(),
|
|
160
|
+
trigger: describedTriggerSchema.optional(),
|
|
161
|
+
registration: z
|
|
162
|
+
.object({ unsubscribe: z.boolean(), hash: z.string(), module: z.string() })
|
|
163
|
+
.optional(),
|
|
164
|
+
problems: z.array(z.string()),
|
|
165
|
+
});
|
|
166
|
+
export const authHookNameSchema = z.enum(AUTH_HOOK_NAMES);
|
|
167
|
+
/** What `zitejs describe` and a build's describe invoke answer. */
|
|
168
|
+
export const describeOutputSchema = z.object({
|
|
169
|
+
functions: z.array(describedFunctionSchema),
|
|
170
|
+
routes: z.array(describedRouteSchema),
|
|
171
|
+
pages: z.array(describedPageSchema),
|
|
172
|
+
workflows: z.array(describedWorkflowSchema),
|
|
173
|
+
authHooks: z.array(authHookNameSchema),
|
|
174
|
+
problems: z.array(z.string()),
|
|
175
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from 'vitest';
|
|
2
|
+
// Equal, which is stricter than assignable both ways: the schema can neither drop, add nor loosen a field.
|
|
3
|
+
describe("describe's output schema", () => {
|
|
4
|
+
it('infers exactly Description', () => {
|
|
5
|
+
expectTypeOf().toEqualTypeOf();
|
|
6
|
+
});
|
|
7
|
+
it('infers exactly each part, for a consumer to extend', () => {
|
|
8
|
+
expectTypeOf().toEqualTypeOf();
|
|
9
|
+
expectTypeOf().toEqualTypeOf();
|
|
10
|
+
expectTypeOf().toEqualTypeOf();
|
|
11
|
+
expectTypeOf().toEqualTypeOf();
|
|
12
|
+
expectTypeOf().toEqualTypeOf();
|
|
13
|
+
expectTypeOf().toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
it('fails on a drift', () => {
|
|
16
|
+
expectTypeOf()
|
|
17
|
+
// @ts-expect-error a field the type lacks
|
|
18
|
+
.toEqualTypeOf();
|
|
19
|
+
expectTypeOf()
|
|
20
|
+
// @ts-expect-error a kind the type lacks
|
|
21
|
+
.toEqualTypeOf();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -7,4 +7,4 @@ export type { ZiteTrigger, ZiteTriggerSubscribe, ZiteTriggerSubscribeInput, Zite
|
|
|
7
7
|
export { anyone, signedIn, webhook } from './access.js';
|
|
8
8
|
export { publicFn, signedInFn } from './factories.js';
|
|
9
9
|
export { loginHref } from './login.js';
|
|
10
|
-
export { hasRole, role } from './roles.js';
|
|
10
|
+
export { hasRole, role, type RoleId, type ZiteRoles } from './roles.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { isReservedIntegrationId, RESERVED_INTEGRATION_IDS, } from '../internal/reservedIds.js';
|
|
2
|
+
export { authHookNameSchema, describedAccessSchema, describedFunctionSchema, describedPageSchema, describedRouteSchema, describedScheduleSchema, describedTriggerSchema, describedWorkflowSchema, describeOutputSchema, } from './describe/schema.js';
|
|
2
3
|
export type { AppContext, ExpiringToken, HostConnection, HostMode, HostPage, HostProps, PlatformBinding, SiteHead, WebManifest, } from './types.js';
|
|
3
4
|
/** What the host dispatches a request to do beside serving it; without props, only `warm` and `describe`. */
|
|
4
5
|
export declare const INVOKE_KINDS: readonly ["webhook", "describe", "workflow", "register", "warm", "authHook", "function"];
|
|
@@ -17,3 +18,9 @@ export declare const GATEWAY_CONNECTION_HEADER = "x-zite-gateway-connection";
|
|
|
17
18
|
/** On a demo's refused answer, beside its 403, so the platform's runtime shows the demo notice. */
|
|
18
19
|
export declare const ERROR_CODE_HEADER = "x-zite-error-code";
|
|
19
20
|
export declare const DEMO_READ_ONLY_CODE = "DEMO_READ_ONLY";
|
|
21
|
+
/**
|
|
22
|
+
* What a Start app installs beside zitejs, exactly: the TanStack peers zitejs pins, and React Query with its core,
|
|
23
|
+
* pinned together so only one query-core is ever installed. tests/startAppDependencies.test.ts holds it to
|
|
24
|
+
* package.json.
|
|
25
|
+
*/
|
|
26
|
+
export declare const START_APP_DEPENDENCIES: Readonly<Record<string, string>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
// What a Start build and the platform's host say to each other on the wire. Import-free but for the reserved ids
|
|
2
|
-
//
|
|
1
|
+
// What a Start build and the platform's host say to each other on the wire. Import-free but for the reserved ids and
|
|
2
|
+
// describe's output schema, which imports only zod and the auth hook names, so the host takes these without loading
|
|
3
|
+
// anything of zitejs.
|
|
3
4
|
export { isReservedIntegrationId, RESERVED_INTEGRATION_IDS, } from '../internal/reservedIds.js';
|
|
5
|
+
export { authHookNameSchema, describedAccessSchema, describedFunctionSchema, describedPageSchema, describedRouteSchema, describedScheduleSchema, describedTriggerSchema, describedWorkflowSchema, describeOutputSchema, } from './describe/schema.js';
|
|
4
6
|
/** What the host dispatches a request to do beside serving it; without props, only `warm` and `describe`. */
|
|
5
7
|
export const INVOKE_KINDS = [
|
|
6
8
|
'webhook',
|
|
@@ -25,3 +27,16 @@ export const GATEWAY_CONNECTION_HEADER = 'x-zite-gateway-connection';
|
|
|
25
27
|
/** On a demo's refused answer, beside its 403, so the platform's runtime shows the demo notice. */
|
|
26
28
|
export const ERROR_CODE_HEADER = 'x-zite-error-code';
|
|
27
29
|
export const DEMO_READ_ONLY_CODE = 'DEMO_READ_ONLY';
|
|
30
|
+
/**
|
|
31
|
+
* What a Start app installs beside zitejs, exactly: the TanStack peers zitejs pins, and React Query with its core,
|
|
32
|
+
* pinned together so only one query-core is ever installed. tests/startAppDependencies.test.ts holds it to
|
|
33
|
+
* package.json.
|
|
34
|
+
*/
|
|
35
|
+
export const START_APP_DEPENDENCIES = {
|
|
36
|
+
'@tanstack/query-core': '5.104.0',
|
|
37
|
+
'@tanstack/react-query': '5.104.0',
|
|
38
|
+
'@tanstack/react-router': '1.170.45',
|
|
39
|
+
'@tanstack/react-router-ssr-query': '1.167.3',
|
|
40
|
+
'@tanstack/react-start': '1.169.3',
|
|
41
|
+
'@tanstack/start-storage-context': '1.167.40',
|
|
42
|
+
};
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import type { User } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The workspace's role ids, as keys. `zitejs check` and `zitejs generate` fill it in the app's `.zite/roles.d.ts` from
|
|
4
|
+
* the built-ins and `zite.permissions.json`, so a mistyped id fails the typecheck instead of refusing every caller.
|
|
5
|
+
*/
|
|
6
|
+
export interface ZiteRoles {
|
|
7
|
+
}
|
|
8
|
+
/** A role id the workspace defines, or any string where nothing fills `ZiteRoles`. Cast one read from data. */
|
|
9
|
+
export type RoleId = [keyof ZiteRoles] extends [never] ? string : keyof ZiteRoles & string;
|
|
2
10
|
/**
|
|
3
11
|
* By the role's id, as classic's does: a role's name can change. Takes the user, or a context carrying one as
|
|
4
12
|
* classic's `hasRole(context, id)` does; signed out, no one has a role.
|
|
5
13
|
*/
|
|
6
14
|
export declare const hasRole: (who: User | {
|
|
7
15
|
user: User | null;
|
|
8
|
-
} | null | undefined, roleId:
|
|
16
|
+
} | null | undefined, roleId: RoleId) => boolean;
|
|
9
17
|
/** Signed-in users with this role, by its id. */
|
|
10
|
-
export declare const role: (id:
|
|
18
|
+
export declare const role: (id: RoleId) => import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, readonly [import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, {
|
|
11
19
|
user: User;
|
|
12
20
|
}>], undefined>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Import-free, so describe's output schema in zitejs/start/protocol can name them.
|
|
2
|
+
export const AUTH_HOOK_NAMES = [
|
|
3
|
+
'beforeSignUp',
|
|
4
|
+
'beforeSignIn',
|
|
5
|
+
'afterSignUp',
|
|
6
|
+
'afterSignIn',
|
|
7
|
+
'verifySession',
|
|
8
|
+
];
|
|
9
|
+
export const isAuthHookName = (name) => AUTH_HOOK_NAMES.includes(name);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export type AuthHookName
|
|
1
|
+
import { type AuthHookName } from './authHookNames.js';
|
|
2
|
+
export { AUTH_HOOK_NAMES, isAuthHookName, type AuthHookName, } from './authHookNames.js';
|
|
3
3
|
type AuthHook = (input: unknown) => unknown;
|
|
4
|
-
export declare const isAuthHookName: (name: string) => name is AuthHookName;
|
|
5
4
|
/** The hooks the app's `zite.auth.ts` defines, by name. */
|
|
6
5
|
export declare function loadAuthHooks(): Promise<Partial<Record<AuthHookName, AuthHook>>>;
|
|
7
|
-
export {};
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { authHooksModule } from '../build/placeholders/authHooksModule.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
'beforeSignIn',
|
|
5
|
-
'afterSignUp',
|
|
6
|
-
'afterSignIn',
|
|
7
|
-
'verifySession',
|
|
8
|
-
];
|
|
9
|
-
export const isAuthHookName = (name) => AUTH_HOOK_NAMES.includes(name);
|
|
2
|
+
import { AUTH_HOOK_NAMES } from './authHookNames.js';
|
|
3
|
+
export { AUTH_HOOK_NAMES, isAuthHookName, } from './authHookNames.js';
|
|
10
4
|
/** The hooks the app's `zite.auth.ts` defines, by name. */
|
|
11
5
|
export async function loadAuthHooks() {
|
|
12
6
|
if (!authHooksModule)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ZITEJS_VERSION = "0.10.
|
|
1
|
+
export declare const ZITEJS_VERSION = "0.10.2";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Written by scripts/write-version.mjs from package.json.
|
|
2
|
-
export const ZITEJS_VERSION = '0.10.
|
|
2
|
+
export const ZITEJS_VERSION = '0.10.2';
|
package/dist/esm/vite/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { parse } from '@babel/parser';
|
|
2
2
|
import MagicString from 'magic-string';
|
|
3
|
-
import { readFileSync } from 'fs';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
import { walk } from 'estree-walker';
|
|
6
5
|
import { domTagNames } from './domTagNames.js';
|
|
@@ -64,51 +63,11 @@ function classifyElement(name) {
|
|
|
64
63
|
}
|
|
65
64
|
return null;
|
|
66
65
|
}
|
|
67
|
-
/**
|
|
68
|
-
* What zitejs/query needs to keep data on the device, in a built page: an id
|
|
69
|
-
* for this build, so data an older build saved is never shown, and the app's
|
|
70
|
-
* `deviceCache` from `zite.config.json` beside the vite config. Only `"disk"`
|
|
71
|
-
* keeps anything: an app that hasn't chosen, or whose config can't be read,
|
|
72
|
-
* keeps nothing.
|
|
73
|
-
*/
|
|
74
|
-
const deviceCacheTags = (appDir, build) => {
|
|
75
|
-
let deviceCache;
|
|
76
|
-
try {
|
|
77
|
-
deviceCache = JSON.parse(readFileSync(path.join(appDir, 'zite.config.json'), 'utf8')).deviceCache;
|
|
78
|
-
}
|
|
79
|
-
catch { }
|
|
80
|
-
return [
|
|
81
|
-
{ tag: 'meta', attrs: { name: 'zite-build', content: build } },
|
|
82
|
-
...(deviceCache === 'disk'
|
|
83
|
-
? []
|
|
84
|
-
: [
|
|
85
|
-
{
|
|
86
|
-
tag: 'meta',
|
|
87
|
-
attrs: { name: 'zite-device-cache', content: 'memory' },
|
|
88
|
-
},
|
|
89
|
-
]),
|
|
90
|
-
];
|
|
91
|
-
};
|
|
92
66
|
export function ziteId() {
|
|
93
67
|
const cwd = process.cwd();
|
|
94
|
-
let appDir = cwd;
|
|
95
|
-
let building = false;
|
|
96
|
-
// One per build, shared by every page of it.
|
|
97
|
-
const build = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
98
68
|
return {
|
|
99
69
|
name: 'vite-plugin-zite-id',
|
|
100
70
|
enforce: 'pre',
|
|
101
|
-
configResolved(config) {
|
|
102
|
-
// Beside the vite config, as the app's own config reads zite.config.json:
|
|
103
|
-
// the build's cwd isn't always the app's directory.
|
|
104
|
-
appDir = config.configFile
|
|
105
|
-
? path.dirname(config.configFile)
|
|
106
|
-
: config.root;
|
|
107
|
-
building = config.command === 'build';
|
|
108
|
-
},
|
|
109
|
-
transformIndexHtml() {
|
|
110
|
-
return building ? deviceCacheTags(appDir, build) : [];
|
|
111
|
-
},
|
|
112
71
|
async transform(code, id) {
|
|
113
72
|
// TanStack's route code splitting moves a route's component into its own module, `route.tsx?tsr-split=…`.
|
|
114
73
|
const file = id.split('?')[0];
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { mkdtempSync, writeFileSync } from 'fs';
|
|
2
|
-
import { tmpdir } from 'os';
|
|
3
1
|
import path from 'path';
|
|
4
2
|
import { describe, expect, it } from 'vitest';
|
|
5
3
|
import { ziteId } from './index.js';
|
|
@@ -112,37 +110,3 @@ describe('ziteId', () => {
|
|
|
112
110
|
expect(await transform(source)).toBe(source);
|
|
113
111
|
});
|
|
114
112
|
});
|
|
115
|
-
describe("ziteId's tags for zitejs/query's device cache", () => {
|
|
116
|
-
const plugin = (command, config) => {
|
|
117
|
-
const dir = mkdtempSync(path.join(tmpdir(), 'zite-app-'));
|
|
118
|
-
if (config) {
|
|
119
|
-
writeFileSync(path.join(dir, 'zite.config.json'), JSON.stringify(config));
|
|
120
|
-
}
|
|
121
|
-
const instance = ziteId();
|
|
122
|
-
instance.configResolved({
|
|
123
|
-
command,
|
|
124
|
-
configFile: path.join(dir, 'vite.config.ts'),
|
|
125
|
-
root: process.cwd(),
|
|
126
|
-
});
|
|
127
|
-
return () => Object.fromEntries(instance.transformIndexHtml().map(t => [
|
|
128
|
-
t.attrs?.name,
|
|
129
|
-
t.attrs?.content,
|
|
130
|
-
]));
|
|
131
|
-
};
|
|
132
|
-
it('keeps data on the device only for an app that chose disk', () => {
|
|
133
|
-
expect(plugin('build', { deviceCache: 'disk' })()['zite-device-cache']).toBeUndefined();
|
|
134
|
-
expect(plugin('build', { deviceCache: 'memory' })()['zite-device-cache']).toBe('memory');
|
|
135
|
-
expect(plugin('build', { id: 'app' })()['zite-device-cache']).toBe('memory');
|
|
136
|
-
expect(plugin('build')()['zite-device-cache']).toBe('memory');
|
|
137
|
-
});
|
|
138
|
-
it('gives every page of a build the same id, and each build its own', () => {
|
|
139
|
-
const pages = plugin('build', { deviceCache: 'disk' });
|
|
140
|
-
const id = pages()['zite-build'];
|
|
141
|
-
expect(id).toMatch(/\w{6,}/);
|
|
142
|
-
expect(pages()['zite-build']).toBe(id);
|
|
143
|
-
expect(plugin('build', { deviceCache: 'disk' })()['zite-build']).not.toBe(id);
|
|
144
|
-
});
|
|
145
|
-
it('tags nothing on a dev server', () => {
|
|
146
|
-
expect(plugin('serve', { deviceCache: 'disk' })()).toEqual({});
|
|
147
|
-
});
|
|
148
|
-
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "The Zite framework — build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -28,15 +28,6 @@
|
|
|
28
28
|
"require": "./dist/cjs/caller/index.js",
|
|
29
29
|
"default": "./dist/esm/caller/index.js"
|
|
30
30
|
},
|
|
31
|
-
"./query": {
|
|
32
|
-
"zite-start": {
|
|
33
|
-
"types": "./dist/esm/start/classicOnly.d.ts"
|
|
34
|
-
},
|
|
35
|
-
"types": "./dist/esm/query/index.d.ts",
|
|
36
|
-
"import": "./dist/esm/query/index.js",
|
|
37
|
-
"require": "./dist/cjs/query/index.js",
|
|
38
|
-
"default": "./dist/esm/query/index.js"
|
|
39
|
-
},
|
|
40
31
|
"./runtime": {
|
|
41
32
|
"types": "./dist/esm/runtime/index.d.ts",
|
|
42
33
|
"import": "./dist/esm/runtime/index.js",
|
|
@@ -159,6 +150,7 @@
|
|
|
159
150
|
"import": "./dist/esm/start/build/vite.js",
|
|
160
151
|
"default": "./dist/esm/start/build/vite.js"
|
|
161
152
|
},
|
|
153
|
+
"./start/tsconfig.json": "./tsconfig/start.json",
|
|
162
154
|
"./signin": {
|
|
163
155
|
"types": "./dist/esm/signin/index.d.ts",
|
|
164
156
|
"import": "./dist/esm/signin/index.js",
|
|
@@ -177,7 +169,7 @@
|
|
|
177
169
|
},
|
|
178
170
|
"scripts": {
|
|
179
171
|
"build": "node scripts/write-version.mjs && tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
180
|
-
"test": "vitest run
|
|
172
|
+
"test": "vitest run",
|
|
181
173
|
"test:start": "node tests/start/run-contract.mjs",
|
|
182
174
|
"test:start:sdk": "node tests/start/sdk/run.mjs",
|
|
183
175
|
"test:watch": "vitest",
|
|
@@ -193,7 +185,8 @@
|
|
|
193
185
|
"*": "oxfmt --write --no-error-on-unmatched-pattern --"
|
|
194
186
|
},
|
|
195
187
|
"files": [
|
|
196
|
-
"dist"
|
|
188
|
+
"dist",
|
|
189
|
+
"tsconfig"
|
|
197
190
|
],
|
|
198
191
|
"typesVersions": {
|
|
199
192
|
"*": {
|
|
@@ -294,7 +287,6 @@
|
|
|
294
287
|
"openai": "6.16.0",
|
|
295
288
|
"oxfmt": "0.73.0",
|
|
296
289
|
"react": "^19.0.0",
|
|
297
|
-
"react-query-5749": "npm:@tanstack/react-query@5.74.9",
|
|
298
290
|
"typescript": "^5.4.0",
|
|
299
291
|
"vite": "^8.3.4",
|
|
300
292
|
"vitest": "^4.1.12"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "${configDir}/.tsbuildinfo",
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"customConditions": ["zite-start"],
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"types": ["vite/client"],
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"moduleDetection": "force",
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"incremental": true,
|
|
17
|
+
"strict": false,
|
|
18
|
+
"strictNullChecks": true,
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
"paths": {
|
|
21
|
+
"@/*": ["${configDir}/src/*"],
|
|
22
|
+
"~/*": ["${configDir}/src/*"],
|
|
23
|
+
"@project/components/*": ["${configDir}/../../packages/components/*"],
|
|
24
|
+
"zitejs/db": ["${configDir}/../../.zite/db.ts"],
|
|
25
|
+
"zitejs/integrations": ["${configDir}/.zite/integrations/index.ts"],
|
|
26
|
+
"zitejs/email": ["${configDir}/.zite/integrations/email.ts"],
|
|
27
|
+
"zitejs/meta": ["${configDir}/.zite/meta.ts"],
|
|
28
|
+
"react": ["${configDir}/node_modules/@types/react"],
|
|
29
|
+
"react/*": ["${configDir}/node_modules/@types/react/*"],
|
|
30
|
+
"react-dom": ["${configDir}/node_modules/@types/react-dom"],
|
|
31
|
+
"react-dom/*": ["${configDir}/node_modules/@types/react-dom/*"]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"include": [
|
|
35
|
+
"${configDir}/src",
|
|
36
|
+
"${configDir}/.zite/*.d.ts",
|
|
37
|
+
"${configDir}/vite.config.ts"
|
|
38
|
+
],
|
|
39
|
+
"exclude": ["${configDir}/node_modules", "${configDir}/dist"]
|
|
40
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMode = getMode;
|
|
4
|
-
/** Whether this page is a live app or one of the platform's previews (the editor, snapshots, sandboxes). */
|
|
5
|
-
function getMode() {
|
|
6
|
-
if (typeof window === 'undefined')
|
|
7
|
-
return 'preview';
|
|
8
|
-
const host = window.location.host;
|
|
9
|
-
return host.startsWith('zite-editor') ||
|
|
10
|
-
host.startsWith('zite-action-') ||
|
|
11
|
-
host.startsWith('zite-snapshot-') ||
|
|
12
|
-
host.endsWith('.zite-dev-sandbox.com') ||
|
|
13
|
-
host.endsWith('.zite-sandbox.com') ||
|
|
14
|
-
host.endsWith('.zite-dev-app.com') ||
|
|
15
|
-
host.endsWith('.zite-app.com')
|
|
16
|
-
? 'preview'
|
|
17
|
-
: 'live';
|
|
18
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const DEVICE_CACHE_KEY = "zite:query-cache";
|
|
2
|
-
export declare const DEVICE_CACHE_OWNER_KEY = "zite:query-cache:owner";
|
|
3
|
-
export declare const SESSION_CHANGED_EVENT = "zite:session-changed";
|
|
4
|
-
/**
|
|
5
|
-
* Clears what the app kept on this device, and stops every tab from saving it
|
|
6
|
-
* again until it has checked who is signed in. Runs before a sign-out reaches
|
|
7
|
-
* the server, so it holds offline too.
|
|
8
|
-
*/
|
|
9
|
-
export declare const forgetDeviceCache: () => void;
|
|
10
|
-
/** Who is signed in on this page changed: forget, and have zitejs/query check again. */
|
|
11
|
-
export declare const sessionChanged: () => void;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sessionChanged = exports.forgetDeviceCache = exports.SESSION_CHANGED_EVENT = exports.DEVICE_CACHE_OWNER_KEY = exports.DEVICE_CACHE_KEY = void 0;
|
|
4
|
-
// What zitejs/query keeps on the device. An app has its own origin, so one key.
|
|
5
|
-
exports.DEVICE_CACHE_KEY = 'zite:query-cache';
|
|
6
|
-
// Who that belongs to, kept apart so every tab can check it cheaply.
|
|
7
|
-
exports.DEVICE_CACHE_OWNER_KEY = 'zite:query-cache:owner';
|
|
8
|
-
exports.SESSION_CHANGED_EVENT = 'zite:session-changed';
|
|
9
|
-
/**
|
|
10
|
-
* Clears what the app kept on this device, and stops every tab from saving it
|
|
11
|
-
* again until it has checked who is signed in. Runs before a sign-out reaches
|
|
12
|
-
* the server, so it holds offline too.
|
|
13
|
-
*/
|
|
14
|
-
const forgetDeviceCache = () => {
|
|
15
|
-
try {
|
|
16
|
-
localStorage.setItem(exports.DEVICE_CACHE_OWNER_KEY, JSON.stringify({ owner: null, at: Date.now() }));
|
|
17
|
-
localStorage.removeItem(exports.DEVICE_CACHE_KEY);
|
|
18
|
-
}
|
|
19
|
-
catch { }
|
|
20
|
-
};
|
|
21
|
-
exports.forgetDeviceCache = forgetDeviceCache;
|
|
22
|
-
/** Who is signed in on this page changed: forget, and have zitejs/query check again. */
|
|
23
|
-
const sessionChanged = () => {
|
|
24
|
-
(0, exports.forgetDeviceCache)();
|
|
25
|
-
if (typeof window !== 'undefined') {
|
|
26
|
-
window.dispatchEvent(new Event(exports.SESSION_CHANGED_EVENT));
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports.sessionChanged = sessionChanged;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type QueryClient } from '@tanstack/react-query';
|
|
2
|
-
/**
|
|
3
|
-
* Keeps what the app's queries return in localStorage for whoever is signed
|
|
4
|
-
* in, so a reload or a return visit shows it at once and then refetches it.
|
|
5
|
-
*
|
|
6
|
-
* Signed-out visitors' data is shown before the first render; a signed-in
|
|
7
|
-
* user's only once get-session confirms the same user. Each save is labelled
|
|
8
|
-
* with who get-session last said this page is for, so any sign-in or sign-out
|
|
9
|
-
* this page hears of (zitejs/auth on this page, another tab, a 401) clears the
|
|
10
|
-
* device and the screen when the answer changes.
|
|
11
|
-
*/
|
|
12
|
-
export declare function keepOnDevice(client: QueryClient, { onOwnerChange }?: {
|
|
13
|
-
onOwnerChange?: () => void;
|
|
14
|
-
}): void;
|