@eskais/app-sdk 0.0.0-stage → 0.1.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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -2
  3. package/dist/action/action.d.ts +74 -0
  4. package/dist/action/action.js +106 -0
  5. package/dist/cli/cli.d.ts +2 -0
  6. package/dist/cli/cli.js +51 -0
  7. package/dist/cli/routes.d.ts +17 -0
  8. package/dist/cli/routes.js +36 -0
  9. package/dist/core/assume.d.ts +1 -0
  10. package/dist/core/assume.js +8 -0
  11. package/dist/core/constants.d.ts +302 -0
  12. package/dist/core/constants.js +156 -0
  13. package/dist/core/contracts.d.ts +100 -0
  14. package/dist/core/contracts.js +3 -0
  15. package/dist/core/data-labels.d.ts +196 -0
  16. package/dist/core/data-labels.js +345 -0
  17. package/dist/core/errors.d.ts +46 -0
  18. package/dist/core/errors.js +166 -0
  19. package/dist/core/guards.d.ts +9 -0
  20. package/dist/core/guards.js +14 -0
  21. package/dist/core/refusal.d.ts +30 -0
  22. package/dist/core/refusal.js +53 -0
  23. package/dist/draft/draft.d.ts +36 -0
  24. package/dist/draft/draft.js +87 -0
  25. package/dist/export/csv.d.ts +25 -0
  26. package/dist/export/csv.js +59 -0
  27. package/dist/import/csv-parse.d.ts +11 -0
  28. package/dist/import/csv-parse.js +70 -0
  29. package/dist/import/import.d.ts +102 -0
  30. package/dist/import/import.js +263 -0
  31. package/dist/index.d.ts +31 -0
  32. package/dist/index.js +30 -0
  33. package/dist/navigation/nav.d.ts +119 -0
  34. package/dist/navigation/nav.js +278 -0
  35. package/dist/navigation/router.d.ts +81 -0
  36. package/dist/navigation/router.js +249 -0
  37. package/dist/navigation/shortcuts.d.ts +37 -0
  38. package/dist/navigation/shortcuts.js +93 -0
  39. package/dist/next/index.d.ts +3 -0
  40. package/dist/next/index.js +3 -0
  41. package/dist/next/screen-hydration.d.ts +12 -0
  42. package/dist/next/screen-hydration.js +26 -0
  43. package/dist/next/screen.d.ts +25 -0
  44. package/dist/next/screen.js +44 -0
  45. package/dist/next/server/handler.d.ts +39 -0
  46. package/dist/next/server/handler.js +190 -0
  47. package/dist/next/server/index.d.ts +5 -0
  48. package/dist/next/server/index.js +5 -0
  49. package/dist/next/server/page.d.ts +57 -0
  50. package/dist/next/server/page.js +103 -0
  51. package/dist/next/server/prefetch.d.ts +29 -0
  52. package/dist/next/server/prefetch.js +97 -0
  53. package/dist/next/server/session.d.ts +12 -0
  54. package/dist/next/server/session.js +10 -0
  55. package/dist/next/use-next-router.d.ts +21 -0
  56. package/dist/next/use-next-router.js +104 -0
  57. package/dist/react/data-layer.d.ts +31 -0
  58. package/dist/react/data-layer.js +31 -0
  59. package/dist/react/hooks/use-action.d.ts +12 -0
  60. package/dist/react/hooks/use-action.js +67 -0
  61. package/dist/react/hooks/use-better-auth.d.ts +12 -0
  62. package/dist/react/hooks/use-better-auth.js +11 -0
  63. package/dist/react/hooks/use-draft.d.ts +5 -0
  64. package/dist/react/hooks/use-draft.js +17 -0
  65. package/dist/react/hooks/use-nav.d.ts +17 -0
  66. package/dist/react/hooks/use-nav.js +34 -0
  67. package/dist/react/hooks/use-resource.d.ts +69 -0
  68. package/dist/react/hooks/use-resource.js +218 -0
  69. package/dist/react/hooks/use-view.d.ts +6 -0
  70. package/dist/react/hooks/use-view.js +24 -0
  71. package/dist/react/index.d.ts +8 -0
  72. package/dist/react/index.js +8 -0
  73. package/dist/react/keys.d.ts +51 -0
  74. package/dist/react/keys.js +67 -0
  75. package/dist/resource/form-schema.d.ts +11 -0
  76. package/dist/resource/form-schema.js +51 -0
  77. package/dist/resource/relations.d.ts +99 -0
  78. package/dist/resource/relations.js +194 -0
  79. package/dist/resource/resource-relations.d.ts +44 -0
  80. package/dist/resource/resource-relations.js +141 -0
  81. package/dist/resource/resource-schema.d.ts +9 -0
  82. package/dist/resource/resource-schema.js +73 -0
  83. package/dist/resource/resource-types.d.ts +281 -0
  84. package/dist/resource/resource-types.js +1 -0
  85. package/dist/resource/resource.d.ts +11 -0
  86. package/dist/resource/resource.js +354 -0
  87. package/dist/resource/schema.d.ts +57 -0
  88. package/dist/resource/schema.js +115 -0
  89. package/dist/services/from-page-source.d.ts +15 -0
  90. package/dist/services/from-page-source.js +27 -0
  91. package/dist/services/memory-query.d.ts +8 -0
  92. package/dist/services/memory-query.js +165 -0
  93. package/dist/services/memory-service.d.ts +33 -0
  94. package/dist/services/memory-service.js +291 -0
  95. package/dist/services/rest-service.d.ts +62 -0
  96. package/dist/services/rest-service.js +220 -0
  97. package/dist/services/rng.d.ts +9 -0
  98. package/dist/services/rng.js +22 -0
  99. package/dist/services/spring-service.d.ts +58 -0
  100. package/dist/services/spring-service.js +132 -0
  101. package/dist/session/better-auth.d.ts +83 -0
  102. package/dist/session/better-auth.js +86 -0
  103. package/dist/session/session.d.ts +45 -0
  104. package/dist/session/session.js +36 -0
  105. package/dist/view/preferences.d.ts +35 -0
  106. package/dist/view/preferences.js +93 -0
  107. package/dist/view/view-types.d.ts +122 -0
  108. package/dist/view/view-types.js +1 -0
  109. package/dist/view/view-url.d.ts +7 -0
  110. package/dist/view/view-url.js +54 -0
  111. package/dist/view/view.d.ts +4 -0
  112. package/dist/view/view.js +392 -0
  113. package/package.json +85 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pablo Otero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # @eskais/app-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A declarative application layer over [Eskais UI](https://ui.eskais.com/). Describe your data and what can be done with it (resources, actions, views, navigation and permissions) and the Eskais UI resource and nav blocks give you the screens. The full guide is [ui.eskais.com/docs/app-sdk](https://ui.eskais.com/docs/app-sdk/).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @eskais/app-sdk @tanstack/react-query zod
9
+ npx shadcn@latest add @eskais/resource-page @eskais/nav-shell @eskais/nav-breadcrumb
10
+ ```
11
+
12
+ The blocks pin the version of this package they were built with, and `shadcn add` installs it.
13
+
14
+ ## Entries
15
+
16
+ | Entry | What it has |
17
+ | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18
+ | `@eskais/app-sdk` | No React and no dependencies: `defineResource`, `defineAction`, `defineView`, `defineNav`, `defineDraft`, `defineImport`, relations (`belongsTo`, `hasMany`, `manyToMany`, `embeds`, `resolveRelations`), the `ResourceService` contract with `memoryService`, `restService`, `springService` and `fromPageSource`, sessions (`createSession`, `fromCasl`, `betterAuthSession`), routers, shortcuts, errors and labels |
19
+ | `@eskais/app-sdk/react` | `DataLayer` and the hooks (`useResourceList`, `useResource`, `useResourceMutations`, `useAction`, `useView`, `useNav`, `useDraft`, `useBetterAuthSession`…) on TanStack Query |
20
+ | `@eskais/app-sdk/next` | The Next.js App Router in the browser: `useNextRouter`, `ScreenHydration` and the path helpers (`navScreen`, `pathOfParams`) |
21
+ | `@eskais/app-sdk/next/server` | Server components and route handlers: `navPage` and `resourcePage` (a catch-all page with its query prefetched and hydrated, `generateMetadata` and `notFound()`), `nextSession` and `resourceHandler` |
22
+ | `app-sdk` (bin) | `app-sdk routes`: TanStack Router file routes for each resource |
23
+
24
+ React 19, `@tanstack/react-query` 5, Zod 4, `@tanstack/react-router` 1 and Next.js 15 or 16 are optional peers: the core needs none of them.
25
+
26
+ On Next.js, one optional catch-all serves every resource of the manifest, rendered on the server with its data:
27
+
28
+ ```tsx
29
+ // app/(admin)/[[...path]]/page.tsx
30
+ import { navPage } from "@eskais/app-sdk/next/server"
31
+
32
+ const page = navPage(nav, { render: () => <AdminScreen />, session: getSession, services: backend })
33
+
34
+ export default page.Page
35
+ export const generateMetadata = page.generateMetadata
36
+ ```
37
+
38
+ The guide's [Next.js section](https://ui.eskais.com/docs/guides/app-sdk/#nextjs) has the layout, the session and the route handlers.
39
+
40
+ ```tsx
41
+ import { dataLabelsEn, defineResource, hashRouter, memoryService } from "@eskais/app-sdk"
42
+ import { DataLayer } from "@eskais/app-sdk/react"
43
+ import { z } from "zod"
44
+
45
+ import { ResourcePage } from "@/components/ui/resource-page"
46
+ import { createDataClient } from "@/components/ui/server-data"
47
+
48
+ const customer = z.object({ id: z.number(), name: z.string().meta({ title: "Name" }) })
49
+
50
+ const customers = defineResource<z.infer<typeof customer>>()({
51
+ key: "customers",
52
+ label: { one: "Customer", other: "Customers" },
53
+ schema: customer,
54
+ service: memoryService(customer, { seed: 7, count: 40 }),
55
+ title: (c) => c.name,
56
+ })
57
+
58
+ export function App() {
59
+ return (
60
+ <DataLayer client={createDataClient()} router={hashRouter()} labels={dataLabelsEn}>
61
+ <ResourcePage resource={customers} />
62
+ </DataLayer>
63
+ )
64
+ }
65
+ ```
66
+
67
+ ## License
68
+
69
+ MIT
@@ -0,0 +1,74 @@
1
+ import { ActionScope, ActionTargetKind, Concurrency } from "../core/constants.js";
2
+ import type { CallContext } from "../core/contracts.js";
3
+ import { type ServiceError } from "../core/errors.js";
4
+ import { type Allowed, type Refusal } from "../core/refusal.js";
5
+ import type { AnyResource, ToneName } from "../resource/resource.js";
6
+ import { type StandardSchema } from "../resource/schema.js";
7
+ import type { Session } from "../session/session.js";
8
+ export type ActionTarget<T> = {
9
+ kind: typeof ActionTargetKind.none;
10
+ } | {
11
+ kind: typeof ActionTargetKind.row;
12
+ row: T;
13
+ } | {
14
+ kind: typeof ActionTargetKind.rows;
15
+ rows: readonly T[];
16
+ } | {
17
+ kind: typeof ActionTargetKind.query;
18
+ filter: unknown;
19
+ search?: string | undefined;
20
+ except: readonly unknown[];
21
+ };
22
+ export type ActionConfirm = {
23
+ title?: string;
24
+ description?: string;
25
+ tone?: ToneName;
26
+ confirmLabel?: string;
27
+ };
28
+ export type ActionOptions<T, I, R> = {
29
+ id: string;
30
+ label: string;
31
+ icon?: unknown;
32
+ description?: string;
33
+ resource?: AnyResource;
34
+ /** `ActionScope.row` by default when there's a `resource`, `ActionScope.global` otherwise. */
35
+ scope?: ActionScope | readonly ActionScope[];
36
+ input?: StandardSchema<unknown, I>;
37
+ confirm?: boolean | ActionConfirm;
38
+ can?: (row?: T) => boolean | Refusal;
39
+ run: (target: ActionTarget<T>, input: I, context: CallContext) => Promise<R>;
40
+ optimistic?: (row: T, input: I) => T;
41
+ undo?: (target: ActionTarget<T>, result: R, context: CallContext) => Promise<void>;
42
+ /** Resources refreshed afterwards; its own resource always is. */
43
+ invalidates?: readonly AnyResource[];
44
+ success?: string | ((result: R, count: number) => string) | false;
45
+ failure?: string | ((error: ServiceError) => string) | false;
46
+ shortcut?: string;
47
+ /** What a second run does while one is going: `block` refuses it, `switch` aborts the first, `queue` waits. */
48
+ concurrency?: Concurrency;
49
+ };
50
+ export type AnyAction = Action<any, any, any>;
51
+ export type ActionRunOptions = {
52
+ session?: Session | undefined;
53
+ signal?: AbortSignal | undefined;
54
+ };
55
+ export type Action<T = unknown, I = void, R = unknown> = {
56
+ readonly id: string;
57
+ readonly options: ActionOptions<T, I, R>;
58
+ readonly label: string;
59
+ readonly scopes: readonly ActionScope[];
60
+ readonly destructive: boolean;
61
+ readonly confirm: ActionConfirm | undefined;
62
+ check(target: ActionTarget<T>, session?: Session, notAllowed?: string): Allowed;
63
+ parseInput(input: unknown): Promise<I>;
64
+ execute(target: ActionTarget<T>, input: I, options?: ActionRunOptions): Promise<R>;
65
+ running(): boolean;
66
+ countOf(target: ActionTarget<T>): number | undefined;
67
+ rowsOf(target: ActionTarget<T>): readonly T[];
68
+ };
69
+ export declare function defineAction<T = unknown, I = void, R = unknown>(options: ActionOptions<T, I, R>): Action<T, I, R>;
70
+ export declare function isAction(value: unknown): value is AnyAction;
71
+ export declare function actionsOf(resource: {
72
+ actions(): readonly unknown[];
73
+ }): AnyAction[];
74
+ export declare function messageOf<Value extends unknown[]>(option: string | ((...values: Value) => string) | false | undefined, ...values: Value): string | undefined;
@@ -0,0 +1,106 @@
1
+ import { assumeType } from "../core/assume.js";
2
+ import { ActionScope, ActionTargetKind, Concurrency, ServiceErrorKind } from "../core/constants.js";
3
+ import { ServiceFailure, serviceError } from "../core/errors.js";
4
+ import { isFunction, isRecord, isString } from "../core/guards.js";
5
+ import { firstRefusal, toAllowed } from "../core/refusal.js";
6
+ import { isValidationFailure, issuePath, validate } from "../resource/schema.js";
7
+ function scopesOf(scope, hasResource) {
8
+ if (scope === undefined)
9
+ return [hasResource ? ActionScope.row : ActionScope.global];
10
+ return isString(scope) ? [scope] : scope;
11
+ }
12
+ function linked(signal, own) {
13
+ if (!signal)
14
+ return own.signal;
15
+ return AbortSignal.any([signal, own.signal]);
16
+ }
17
+ export function defineAction(options) {
18
+ const scopes = scopesOf(options.scope, options.resource !== undefined);
19
+ const confirm = options.confirm === true ? {} : options.confirm === false ? undefined : options.confirm;
20
+ const concurrency = options.concurrency ?? Concurrency.block;
21
+ let inFlight;
22
+ let tail = Promise.resolve();
23
+ const rowsOf = (target) => {
24
+ if (target.kind === ActionTargetKind.row)
25
+ return [target.row];
26
+ if (target.kind === ActionTargetKind.rows)
27
+ return target.rows;
28
+ return [];
29
+ };
30
+ async function parseInput(input) {
31
+ if (!options.input) {
32
+ // Workaround: an action without an input schema takes no input; `I` is `void` for it.
33
+ return assumeType(input);
34
+ }
35
+ const result = await validate(options.input, input);
36
+ if (!isValidationFailure(result))
37
+ return result.value;
38
+ const fields = result.issues.map((issue) => ({ path: issuePath(issue), message: issue.message }));
39
+ const message = fields.map((field) => (field.path ? `${field.path}: ${field.message}` : field.message)).join("; ");
40
+ throw new ServiceFailure(serviceError(ServiceErrorKind.validation, message, { fields }));
41
+ }
42
+ function start(target, input, run) {
43
+ const controller = new AbortController();
44
+ const done = options.run(target, input, { signal: linked(run.signal, controller), session: run.session });
45
+ const entry = { controller, done };
46
+ inFlight = entry;
47
+ const clear = () => {
48
+ if (inFlight === entry)
49
+ inFlight = undefined;
50
+ };
51
+ done.then(clear, clear);
52
+ return done;
53
+ }
54
+ return {
55
+ id: options.id,
56
+ options,
57
+ label: options.label,
58
+ scopes,
59
+ destructive: confirm?.tone === "destructive",
60
+ confirm,
61
+ check(target, session, notAllowed = "") {
62
+ const rows = rowsOf(target);
63
+ const own = rows.length === 0
64
+ ? [toAllowed(options.can?.(), notAllowed)]
65
+ : rows.map((row) => toAllowed(options.can?.(row), notAllowed));
66
+ const resource = options.resource?.key;
67
+ const fromSession = rows.length === 0
68
+ ? [toAllowed(session?.can(options.id, resource === undefined ? undefined : { resource }), notAllowed)]
69
+ : rows.map((row) => toAllowed(session?.can(options.id, resource === undefined ? undefined : { resource, row }), notAllowed));
70
+ return firstRefusal(...own, ...fromSession);
71
+ },
72
+ parseInput,
73
+ execute(target, input, run = {}) {
74
+ if (inFlight && concurrency === Concurrency.block)
75
+ return Promise.reject(new ServiceFailure(serviceError(ServiceErrorKind.conflict, `${options.id} is already running.`)));
76
+ if (inFlight && concurrency === Concurrency.switch)
77
+ inFlight.controller.abort();
78
+ if (concurrency === Concurrency.queue) {
79
+ const next = tail.then(() => start(target, input, run), () => start(target, input, run));
80
+ tail = next.catch(() => undefined);
81
+ return next;
82
+ }
83
+ return start(target, input, run);
84
+ },
85
+ running: () => inFlight !== undefined,
86
+ countOf(target) {
87
+ if (target.kind === ActionTargetKind.none)
88
+ return 0;
89
+ if (target.kind === ActionTargetKind.query)
90
+ return undefined;
91
+ return rowsOf(target).length;
92
+ },
93
+ rowsOf,
94
+ };
95
+ }
96
+ export function isAction(value) {
97
+ return isRecord(value) && isString(value.id) && isFunction(value.execute) && Array.isArray(value.scopes);
98
+ }
99
+ export function actionsOf(resource) {
100
+ return resource.actions().filter(isAction);
101
+ }
102
+ export function messageOf(option, ...values) {
103
+ if (option === undefined || option === false)
104
+ return undefined;
105
+ return isFunction(option) ? option(...values) : option;
106
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function main(argv: readonly string[], cwd: string, log: (line: string) => void): number;
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { parseArgs } from "node:util";
5
+ import { parseResource, routeFiles } from "./routes.js";
6
+ const usage = `app-sdk routes --from <module> --resource <name[:base[:create[:edit]]]>… [--dir src/routes] [--routes-module <module>] [--force]
7
+
8
+ Writes TanStack Router file routes for each resource: <base>/index.tsx, <base>/<create>.tsx,
9
+ <base>/$id/index.tsx and <base>/$id/<edit>.tsx, one line each with resourceRoute. Existing files stay
10
+ unless --force.`;
11
+ export function main(argv, cwd, log) {
12
+ const [command, ...rest] = argv;
13
+ if (command !== "routes") {
14
+ log(usage);
15
+ return command === undefined || command === "--help" ? 0 : 2;
16
+ }
17
+ const { values } = parseArgs({
18
+ args: [...rest],
19
+ options: {
20
+ from: { type: "string" },
21
+ resource: { type: "string", multiple: true },
22
+ dir: { type: "string", default: "src/routes" },
23
+ "routes-module": { type: "string" },
24
+ force: { type: "boolean", default: false },
25
+ },
26
+ });
27
+ const resources = values.resource ?? [];
28
+ if (values.from === undefined || resources.length === 0) {
29
+ log(usage);
30
+ return 2;
31
+ }
32
+ const files = routeFiles({
33
+ from: values.from,
34
+ resources: resources.map(parseResource),
35
+ ...(values["routes-module"] === undefined ? {} : { routesModule: values["routes-module"] }),
36
+ });
37
+ const root = resolve(cwd, values.dir);
38
+ for (const route of files) {
39
+ const target = join(root, route.path);
40
+ if (existsSync(target) && !values.force) {
41
+ log(`kept ${target}`);
42
+ continue;
43
+ }
44
+ mkdirSync(dirname(target), { recursive: true });
45
+ writeFileSync(target, route.content);
46
+ log(`wrote ${target}`);
47
+ }
48
+ return 0;
49
+ }
50
+ if (import.meta.main === true)
51
+ process.exitCode = main(process.argv.slice(2), process.cwd(), (line) => process.stdout.write(`${line}\n`));
@@ -0,0 +1,17 @@
1
+ export type RouteResource = {
2
+ name: string;
3
+ base: string;
4
+ create: string;
5
+ edit: string;
6
+ };
7
+ export type RoutesOptions = {
8
+ resources: readonly RouteResource[];
9
+ from: string;
10
+ routesModule?: string;
11
+ };
12
+ export type RouteFile = {
13
+ path: string;
14
+ content: string;
15
+ };
16
+ export declare function routeFiles(options: RoutesOptions): RouteFile[];
17
+ export declare function parseResource(spec: string): RouteResource;
@@ -0,0 +1,36 @@
1
+ const quote = (text) => JSON.stringify(text);
2
+ function file(path, route, screen, resource, options) {
3
+ const routesModule = options.routesModule ?? "@/components/ui/resource-routes";
4
+ const content = [
5
+ `import { createFileRoute } from "@tanstack/react-router"`,
6
+ "",
7
+ `import { resourceRoute } from ${quote(routesModule)}`,
8
+ `import { ${resource.name} } from ${quote(options.from)}`,
9
+ "",
10
+ `export const Route = createFileRoute(${quote(route)})(resourceRoute.${screen}(${resource.name}))`,
11
+ "",
12
+ ].join("\n");
13
+ return { path, content };
14
+ }
15
+ export function routeFiles(options) {
16
+ return options.resources.flatMap((resource) => {
17
+ const base = resource.base.replace(/^\/+|\/+$/gu, "");
18
+ return [
19
+ file(`${base}/index.tsx`, `/${base}/`, "list", resource, options),
20
+ file(`${base}/${resource.create}.tsx`, `/${base}/${resource.create}`, "create", resource, options),
21
+ file(`${base}/$id/index.tsx`, `/${base}/$id/`, "detail", resource, options),
22
+ file(`${base}/$id/${resource.edit}.tsx`, `/${base}/$id/${resource.edit}`, "edit", resource, options),
23
+ ];
24
+ });
25
+ }
26
+ const identifier = /^[A-Za-z_$][\w$]*$/u;
27
+ const segment = /^[\w-]+(?:\/[\w-]+)*$/u;
28
+ export function parseResource(spec) {
29
+ const [name = "", base = name, create = "new", edit = "edit"] = spec.split(":");
30
+ if (!identifier.test(name))
31
+ throw new RangeError(`"${name}" isn't an export name.`);
32
+ for (const part of [base, create, edit])
33
+ if (!segment.test(part))
34
+ throw new RangeError(`"${part}" isn't a route segment.`);
35
+ return { name, base, create, edit };
36
+ }
@@ -0,0 +1 @@
1
+ export declare function assumeType<T>(value: unknown): T;
@@ -0,0 +1,8 @@
1
+ function holds(_value) {
2
+ return true;
3
+ }
4
+ export function assumeType(value) {
5
+ if (holds(value))
6
+ return value;
7
+ throw new TypeError("Unreachable.");
8
+ }