zitejs 0.10.0 → 0.10.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.
Files changed (32) hide show
  1. package/dist/cjs/check/index.js +10 -4
  2. package/dist/cjs/start/build/entries.d.ts +5 -0
  3. package/dist/cjs/start/build/entries.js +16 -8
  4. package/dist/cjs/start/build/roleIds.d.ts +11 -0
  5. package/dist/cjs/start/build/roleIds.js +59 -0
  6. package/dist/cjs/start/describe/schema.d.ts +574 -0
  7. package/dist/cjs/start/describe/schema.js +178 -0
  8. package/dist/cjs/start/protocol.d.ts +7 -0
  9. package/dist/cjs/start/protocol.js +27 -3
  10. package/dist/cjs/start/serve/authHookNames.d.ts +3 -0
  11. package/dist/cjs/start/serve/authHookNames.js +13 -0
  12. package/dist/esm/check/index.js +10 -4
  13. package/dist/esm/start/build/entries.d.ts +5 -0
  14. package/dist/esm/start/build/entries.js +15 -8
  15. package/dist/esm/start/build/roleIds.d.ts +11 -0
  16. package/dist/esm/start/build/roleIds.js +54 -0
  17. package/dist/esm/start/describe/schema.d.ts +574 -0
  18. package/dist/esm/start/describe/schema.js +175 -0
  19. package/dist/esm/start/describe/schema.test-d.d.ts +1 -0
  20. package/dist/esm/start/describe/schema.test-d.js +23 -0
  21. package/dist/esm/start/index.d.ts +1 -1
  22. package/dist/esm/start/protocol.d.ts +7 -0
  23. package/dist/esm/start/protocol.js +17 -2
  24. package/dist/esm/start/roles.d.ts +10 -2
  25. package/dist/esm/start/serve/authHookNames.d.ts +3 -0
  26. package/dist/esm/start/serve/authHookNames.js +9 -0
  27. package/dist/esm/start/serve/authHooks.d.ts +2 -4
  28. package/dist/esm/start/serve/authHooks.js +2 -8
  29. package/dist/esm/start/version.d.ts +1 -1
  30. package/dist/esm/start/version.js +1 -1
  31. package/package.json +4 -2
  32. package/tsconfig/start.json +40 -0
@@ -170,14 +170,20 @@ function runTool(file, args, cwd) {
170
170
  }
171
171
  const isMissingModule = (err) => err?.code === 'MODULE_NOT_FOUND';
172
172
  /**
173
- * A Start app, in about a second: its route tree regenerated as `vite build`
174
- * writes it, then a tsgo typecheck, which reads that tree. Everything else is
175
- * the platform build's and its describe's to refuse.
173
+ * A Start app, in about a second: its `.zite/` entries and role ids, and its
174
+ * route tree, written as `vite build` writes them, then a tsgo typecheck, which
175
+ * reads them. Everything else is the platform build's and its describe's to
176
+ * refuse.
176
177
  */
177
178
  async function checkStartApp(reporter, app, appPath) {
178
- const { regenerateRouteTree } = await Promise.resolve().then(() => __importStar(require('./start/routeTree.js')));
179
+ const [{ regenerateRouteTree }, { writeStartFiles }] = await Promise.all([
180
+ Promise.resolve().then(() => __importStar(require('./start/routeTree.js'))),
181
+ Promise.resolve().then(() => __importStar(require('../start/build/entries.js'))),
182
+ ]);
179
183
  let routeTree = { ok: true };
180
184
  try {
185
+ // First: the route tree's footer types the start instance only when .zite/start.ts is there.
186
+ writeStartFiles(appPath);
181
187
  await regenerateRouteTree(appPath);
182
188
  }
183
189
  catch (err) {
@@ -15,6 +15,11 @@ export declare const hasAppStart: (appDir: string) => boolean;
15
15
  export declare const writeIfChanged: (appDir: string, file: string, content: string) => boolean;
16
16
  export declare const isStartAppDir: (appPath: string) => boolean;
17
17
  export declare const workspaceHasStartApps: () => boolean;
18
+ /**
19
+ * The `.zite/` files a Start app's typecheck reads, its entries as `vite build` writes them: `check`, `generate` and
20
+ * `dev` all write them. Returns the ones that changed.
21
+ */
22
+ export declare function writeStartFiles(appDir: string): string[];
18
23
  export declare function regenerateStartEntries(app: SourceDir): void;
19
24
  /**
20
25
  * App modules that mention createAutomation or createProviderTrigger: what the workflow registry imports. Describe
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderWorkflowModules = exports.workspaceHasStartApps = exports.isStartAppDir = exports.writeIfChanged = exports.hasAppStart = exports.renderStartInstance = exports.renderStartServerEntry = exports.START_INSTANCE_ENTRY = exports.START_SERVER_ENTRY = void 0;
4
+ exports.writeStartFiles = writeStartFiles;
4
5
  exports.regenerateStartEntries = regenerateStartEntries;
5
6
  exports.workflowFiles = workflowFiles;
6
7
  const node_fs_1 = require("node:fs");
7
8
  const node_path_1 = require("node:path");
8
9
  const sourceRoots_js_1 = require("../../sourceRoots.js");
10
+ const roleIds_js_1 = require("./roleIds.js");
9
11
  exports.START_SERVER_ENTRY = '.zite/server.ts';
10
12
  exports.START_INSTANCE_ENTRY = '.zite/start.ts';
11
13
  const APP_START_FILES = ['src/start.ts', 'src/start.tsx'];
@@ -75,17 +77,23 @@ exports.isStartAppDir = isStartAppDir;
75
77
  const isStartApp = (app) => (0, exports.isStartAppDir)(app.path);
76
78
  const workspaceHasStartApps = () => (0, sourceRoots_js_1.listSourceDirs)().some(isStartApp);
77
79
  exports.workspaceHasStartApps = workspaceHasStartApps;
80
+ /**
81
+ * The `.zite/` files a Start app's typecheck reads, its entries as `vite build` writes them: `check`, `generate` and
82
+ * `dev` all write them. Returns the ones that changed.
83
+ */
84
+ function writeStartFiles(appDir) {
85
+ const files = [
86
+ [exports.START_SERVER_ENTRY, (0, exports.renderStartServerEntry)()],
87
+ [exports.START_INSTANCE_ENTRY, (0, exports.renderStartInstance)((0, exports.hasAppStart)(appDir))],
88
+ [roleIds_js_1.START_ROLES_FILE, (0, roleIds_js_1.renderRoleIds)((0, roleIds_js_1.workspaceRoleIds)(appDir))],
89
+ ];
90
+ return files.flatMap(([file, content]) => (0, exports.writeIfChanged)(appDir, file, content) ? [file] : []);
91
+ }
78
92
  function regenerateStartEntries(app) {
79
93
  if (!isStartApp(app))
80
94
  return;
81
- const entries = [
82
- [exports.START_SERVER_ENTRY, (0, exports.renderStartServerEntry)()],
83
- [exports.START_INSTANCE_ENTRY, (0, exports.renderStartInstance)((0, exports.hasAppStart)(app.path))],
84
- ];
85
- for (const [file, content] of entries) {
86
- if ((0, exports.writeIfChanged)(app.path, file, content))
87
- console.log(`Wrote ${(0, node_path_1.join)(app.path, file)}`);
88
- }
95
+ for (const file of writeStartFiles(app.path))
96
+ console.log(`Wrote ${(0, node_path_1.join)(app.path, file)}`);
89
97
  }
90
98
  const SOURCE_FILE = /\.[mc]?[jt]sx?$/;
91
99
  const NOT_APP_CODE = /(\.(test|spec)\.[^.]+|\.d\.ts|routeTree\.gen\.ts)$/;
@@ -0,0 +1,11 @@
1
+ export declare const START_ROLES_FILE = ".zite/roles.d.ts";
2
+ /** The roles every workspace has without defining them, as the platform names them. */
3
+ export declare const BUILTIN_ROLE_IDS: readonly ["builtin:all-team-members", "builtin:all-users"];
4
+ /**
5
+ * The built-ins, then the roles the nearest `zite.permissions.json` defines. None at all when there's no readable
6
+ * file, so role ids stay plain strings: a missing or broken file would otherwise type every role the app names as a
7
+ * typo, and the nearest id that compiles is a built-in that admits everyone.
8
+ */
9
+ export declare const workspaceRoleIds: (appDir: string) => string[];
10
+ /** `.zite/roles.d.ts`, which types `role()` and `hasRole` to these ids. Its `export {}` makes it an augmentation. */
11
+ export declare const renderRoleIds: (ids: readonly string[]) => string;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderRoleIds = exports.workspaceRoleIds = exports.BUILTIN_ROLE_IDS = exports.START_ROLES_FILE = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ exports.START_ROLES_FILE = '.zite/roles.d.ts';
7
+ /** The roles every workspace has without defining them, as the platform names them. */
8
+ exports.BUILTIN_ROLE_IDS = [
9
+ 'builtin:all-team-members',
10
+ 'builtin:all-users',
11
+ ];
12
+ const PERMISSIONS_FILE = 'zite.permissions.json';
13
+ // The workspace root's in a monorepo, above apps/<dir>/.
14
+ const findPermissionsFile = (appDir) => {
15
+ for (let dir = (0, node_path_1.resolve)(appDir);; dir = (0, node_path_1.dirname)(dir)) {
16
+ const file = (0, node_path_1.join)(dir, PERMISSIONS_FILE);
17
+ if ((0, node_fs_1.existsSync)(file))
18
+ return file;
19
+ if ((0, node_path_1.dirname)(dir) === dir)
20
+ return undefined;
21
+ }
22
+ };
23
+ // Undefined for a file that isn't a permissions file: its roles can't be known.
24
+ const definedRoleIds = (file) => {
25
+ try {
26
+ const { roles } = (JSON.parse((0, node_fs_1.readFileSync)(file, 'utf-8')) ?? {});
27
+ if (!Array.isArray(roles))
28
+ return undefined;
29
+ return roles.flatMap(role => {
30
+ const id = role?.id;
31
+ return typeof id === 'string' && id ? [id] : [];
32
+ });
33
+ }
34
+ catch {
35
+ return undefined;
36
+ }
37
+ };
38
+ /**
39
+ * The built-ins, then the roles the nearest `zite.permissions.json` defines. None at all when there's no readable
40
+ * file, so role ids stay plain strings: a missing or broken file would otherwise type every role the app names as a
41
+ * typo, and the nearest id that compiles is a built-in that admits everyone.
42
+ */
43
+ const workspaceRoleIds = (appDir) => {
44
+ const file = findPermissionsFile(appDir);
45
+ const defined = file ? definedRoleIds(file) : undefined;
46
+ return defined ? [...new Set([...exports.BUILTIN_ROLE_IDS, ...defined])] : [];
47
+ };
48
+ exports.workspaceRoleIds = workspaceRoleIds;
49
+ /** `.zite/roles.d.ts`, which types `role()` and `hasRole` to these ids. Its `export {}` makes it an augmentation. */
50
+ const renderRoleIds = (ids) => `// Generated by zitejs from the built-in roles and zite.permissions.json. The platform owns this file.
51
+ export {};
52
+
53
+ declare module 'zitejs/start' {
54
+ interface ZiteRoles {
55
+ ${ids.map(id => ` ${JSON.stringify(id)}: true;`).join('\n')}
56
+ }
57
+ }
58
+ `;
59
+ exports.renderRoleIds = renderRoleIds;