@marktiderman/genesis-core 2.0.0 → 2.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.
- package/dist/{chunk-IOTHEKO7.js → chunk-7GW3QR63.js} +45 -12
- package/dist/chunk-7GW3QR63.js.map +1 -0
- package/dist/{chunk-QPD4FKPC.js → chunk-X6EO3XBB.js} +22 -6
- package/dist/chunk-X6EO3XBB.js.map +1 -0
- package/dist/form-types.d.ts +13 -0
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/use-resource-form.d.ts +11 -1
- package/dist/hooks/use-resource-form.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/provider/index.d.ts +18 -3
- package/dist/provider/index.js +1 -1
- package/dist/resource-view/index.d.ts +32 -4
- package/dist/resource-view/index.js +16 -2
- package/dist/resource-view/index.js.map +1 -1
- package/package.json +52 -1
- package/dist/chunk-IOTHEKO7.js.map +0 -1
- package/dist/chunk-QPD4FKPC.js.map +0 -1
|
@@ -99,6 +99,16 @@ interface UseResourceFormReturn {
|
|
|
99
99
|
}
|
|
100
100
|
/** Build default values for a single array item from its sub-field definitions */
|
|
101
101
|
declare function buildArrayItemDefaults(arrayFields: ResourceFormFieldDef[]): Record<string, unknown>;
|
|
102
|
+
/**
|
|
103
|
+
* What a save sends for an input left empty: `""`, or `undefined` (a cleared number input). Only a field whose column the form knows
|
|
104
|
+
* about (`nullable` set, as ResourceView sets it from a generated contract) is changed:
|
|
105
|
+
* a create leaves it out, so the column's default (or null) applies, and an edit the person
|
|
106
|
+
* made clears it to null. Everything else goes as before, `""` included: a field without
|
|
107
|
+
* `nullable`, an edit of a field nobody touched (`changed` doesn't list it), a value the
|
|
108
|
+
* screen started the field at (its `defaultValue`), and a text column that can't be null
|
|
109
|
+
* (on a create, only when it has no default to fall back on).
|
|
110
|
+
*/
|
|
111
|
+
declare function blankValues(values: Record<string, unknown>, fields: readonly ResourceFormFieldDef[], action: "create" | "edit", changed?: ReadonlySet<string>): Record<string, unknown>;
|
|
102
112
|
declare function useResourceForm(options: UseResourceFormOptions): UseResourceFormReturn;
|
|
103
113
|
|
|
104
|
-
export { type UseResourceFormOptions, type UseResourceFormReturn, buildArrayItemDefaults, useResourceForm };
|
|
114
|
+
export { type UseResourceFormOptions, type UseResourceFormReturn, blankValues, buildArrayItemDefaults, useResourceForm };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { buildArrayItemDefaults, useResourceForm } from '../chunk-
|
|
1
|
+
export { blankValues, buildArrayItemDefaults, useResourceForm } from '../chunk-X6EO3XBB.js';
|
|
2
2
|
import '../chunk-GWQHP3RC.js';
|
|
3
3
|
import '../chunk-K4ZNAF3G.js';
|
|
4
4
|
import '../chunk-XQO4OH2N.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { UseDraftReturn, useDraft } from './hooks/use-draft.js';
|
|
|
15
15
|
export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftAdoption, DraftController, DraftOptions, DraftSeed, DraftState, DraftStatus, DraftValue, isNetworkFailure, stableJson } from './hooks/draft-controller.js';
|
|
16
16
|
export { G as GenesisViewerRoles, N as NO_VIEWER, R as ResourceScope, V as Viewer, a as ViewerContext, b as ViewerScope, c as ViewerScopeProps, d as clearViewerCache, s as scopeClock, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from './viewer-scope-bthEYSOB.js';
|
|
17
17
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, LiveOptions } from './hooks/use-live.js';
|
|
18
|
-
export { UseResourceFormOptions, UseResourceFormReturn, buildArrayItemDefaults, useResourceForm } from './hooks/use-resource-form.js';
|
|
18
|
+
export { UseResourceFormOptions, UseResourceFormReturn, blankValues, buildArrayItemDefaults, useResourceForm } from './hooks/use-resource-form.js';
|
|
19
19
|
export { UseWizardReturn, WizardStep, useWizard } from './hooks/use-wizard.js';
|
|
20
20
|
export { DEFAULT_UNDO_DELAY_MS, MutationMode, MutationModeOptions, UndoableWrite, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './hooks/mutation-mode.js';
|
|
21
21
|
export { DEFAULT_UNSAVED_CHANGES_MESSAGE, UseUnsavedChangesGuardOptions, UseUnsavedChangesGuardReturn, useUnsavedChangesGuard } from './hooks/use-unsaved-changes-guard.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from './chunk-
|
|
1
|
+
export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from './chunk-7GW3QR63.js';
|
|
2
2
|
export { defineResource } from './chunk-7FVTGKTX.js';
|
|
3
3
|
export { decodeRecordKey, encodeRecordKey, keyFields } from './chunk-KV2HW4G4.js';
|
|
4
4
|
import './chunk-XCX2TRBL.js';
|
|
@@ -7,7 +7,7 @@ export { WRITE_FAILED, useWrite } from './chunk-52T2EYXH.js';
|
|
|
7
7
|
export { NO_VIEWER } from './chunk-OZYF55E3.js';
|
|
8
8
|
export { useInfiniteResource } from './chunk-2VVZ2KX3.js';
|
|
9
9
|
export { loadRelationLabel, useRelationLabel } from './chunk-XMC4EJUE.js';
|
|
10
|
-
export { buildArrayItemDefaults, useResourceForm } from './chunk-
|
|
10
|
+
export { blankValues, buildArrayItemDefaults, useResourceForm } from './chunk-X6EO3XBB.js';
|
|
11
11
|
export { useOne } from './chunk-GWQHP3RC.js';
|
|
12
12
|
export { useResource } from './chunk-CC37H7O2.js';
|
|
13
13
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from './chunk-K4ZNAF3G.js';
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -58,6 +58,10 @@ interface SupabaseQueryBuilder {
|
|
|
58
58
|
*/
|
|
59
59
|
interface SupabaseClient {
|
|
60
60
|
from(table: string): SupabaseQueryBuilder;
|
|
61
|
+
/** Another schema's tables, for a resource named `schema.table` outside `public`. */
|
|
62
|
+
schema?(name: string): {
|
|
63
|
+
from(table: string): SupabaseQueryBuilder;
|
|
64
|
+
};
|
|
61
65
|
/** Supabase Realtime; needed only for `subscribe` (see `SupabaseProviderOptions.realtime`). */
|
|
62
66
|
channel?(name: string): SupabaseRealtimeChannel;
|
|
63
67
|
/** Releases a channel made by `channel()`. */
|
|
@@ -104,6 +108,10 @@ interface SupabaseRealtimeChannel {
|
|
|
104
108
|
*/
|
|
105
109
|
interface SupabaseClientInput {
|
|
106
110
|
from(table: string): unknown;
|
|
111
|
+
/** Another schema's tables, for a resource named `schema.table` outside `public`. Any real client's `schema` fits. */
|
|
112
|
+
schema?(name: string): {
|
|
113
|
+
from(table: string): unknown;
|
|
114
|
+
};
|
|
107
115
|
/** Database functions, for a resource whose `source` is an `rpc`. Any real client's `rpc` fits. */
|
|
108
116
|
rpc?(fn: string, args?: Record<string, unknown>, options?: {
|
|
109
117
|
count?: "exact" | "planned" | "estimated";
|
|
@@ -231,10 +239,15 @@ interface SupabaseProviderOptions {
|
|
|
231
239
|
* filter). The database reports such a delete as zero rows, so for these
|
|
232
240
|
* the provider checks the row is visible, deletes it, and reads it back:
|
|
233
241
|
* gone from view is success, still visible is `forbidden`. A row that was
|
|
234
|
-
* not visible beforehand is `gone`.
|
|
242
|
+
* not visible beforehand is `gone`. A list matches a `public` table under
|
|
243
|
+
* either spelling; a test is asked once, with the name as the caller gives it.
|
|
235
244
|
*/
|
|
236
245
|
binTables?: readonly string[] | ((resource: string) => boolean);
|
|
237
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* Per-resource rules, keyed by resource name. A `public` resource may be keyed either way
|
|
248
|
+
* (`goals` or `public.goals`). The key spelled exactly as the caller names the resource wins;
|
|
249
|
+
* the other spelling is used only when that key is absent. Rules are never merged.
|
|
250
|
+
*/
|
|
238
251
|
resources?: Record<string, SupabaseResourceConfig>;
|
|
239
252
|
/**
|
|
240
253
|
* Called after every committed create, update and delete, e.g. to
|
|
@@ -263,7 +276,9 @@ interface SupabaseProviderOptions {
|
|
|
263
276
|
* Which resources `subscribe` serves through Supabase Realtime: `true` for
|
|
264
277
|
* all, a list of names, or a test. Off by default; a resource's own
|
|
265
278
|
* `resources[name].realtime` wins. Needs a client with `channel()` (any
|
|
266
|
-
* `@supabase/supabase-js` client).
|
|
279
|
+
* `@supabase/supabase-js` client). A list matches a `public` resource
|
|
280
|
+
* under either spelling; a test is asked once, with the name as the caller
|
|
281
|
+
* gives it.
|
|
267
282
|
*/
|
|
268
283
|
realtime?: boolean | readonly string[] | ((resource: string) => boolean);
|
|
269
284
|
}
|
package/dist/provider/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from '../chunk-
|
|
1
|
+
export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from '../chunk-7GW3QR63.js';
|
|
2
2
|
export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from '../chunk-VDEW4AOS.js';
|
|
3
3
|
import '../chunk-ZYJUEJ4Z.js';
|
|
4
4
|
export { fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from '../chunk-PA6WJE5E.js';
|
|
@@ -156,11 +156,20 @@ type RowPicture = {
|
|
|
156
156
|
readonly kind: "initials";
|
|
157
157
|
readonly text: string;
|
|
158
158
|
};
|
|
159
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* The words a view shows. Each one is a step in a chain, and each step overrides the one before:
|
|
161
|
+
* words derived from the resource's name, then the contract's (`noun`, `nounPlural`, `label`, which
|
|
162
|
+
* `genesis introspect` reads from the table comment's `@genesis {...}`), then these, then the
|
|
163
|
+
* screen's own props. Templates take `{noun}`, `{nouns}`, `{count}` and `{total}`.
|
|
164
|
+
*/
|
|
160
165
|
interface ViewCopy {
|
|
161
|
-
/** One row, in a sentence: "brand". */
|
|
166
|
+
/** One row, in a sentence: "brand". Default: the contract's `noun`, then the table name's singular. */
|
|
162
167
|
noun?: string;
|
|
163
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Several: "brands". Default: the contract's `nounPlural`, then the plural of a `noun` the view or
|
|
170
|
+
* contract gives ("entry" → "entries"); with only a noun derived from the name, the contract's
|
|
171
|
+
* label when it reads as a plural ("People"), else the table name.
|
|
172
|
+
*/
|
|
164
173
|
nounPlural?: string;
|
|
165
174
|
/** The page title. Default: the contract's label, then the plural noun in title case. */
|
|
166
175
|
title?: string;
|
|
@@ -169,7 +178,22 @@ interface ViewCopy {
|
|
|
169
178
|
title?: string;
|
|
170
179
|
body?: string;
|
|
171
180
|
};
|
|
181
|
+
/** The create button. Default "New". */
|
|
172
182
|
create?: string;
|
|
183
|
+
/** The form's title. Default "New {noun}" and "Edit {noun}" (the UI catalogue's `form`). */
|
|
184
|
+
form?: {
|
|
185
|
+
createTitle?: string;
|
|
186
|
+
editTitle?: string;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* The count beside the title. Default "{count} {noun}" for one, "{count} {nouns}" for more, and
|
|
190
|
+
* "{count} of {total}" when filtered (the UI catalogue's `page.count*`).
|
|
191
|
+
*/
|
|
192
|
+
count?: {
|
|
193
|
+
one?: string;
|
|
194
|
+
other?: string;
|
|
195
|
+
filtered?: string;
|
|
196
|
+
};
|
|
173
197
|
}
|
|
174
198
|
/** What `defineView` accepts. */
|
|
175
199
|
interface ViewDefinition<C extends ResourceContract, Row extends DataRow = RowOf<C>> {
|
|
@@ -293,6 +317,10 @@ declare class ViewDefinitionError extends Error {
|
|
|
293
317
|
}
|
|
294
318
|
/** The display a field gets when the view doesn't name one. */
|
|
295
319
|
declare function deriveDisplay(field: FieldSchema): DisplayHint;
|
|
320
|
+
/** A table name's singular, for the default noun. A wrong guess is fixed with `@genesis {"noun"}`. */
|
|
321
|
+
declare function singular(word: string): string;
|
|
322
|
+
/** A noun's plural, the inverse of `singular`: entry → entries, box → boxes, person → people. */
|
|
323
|
+
declare function plural(word: string): string;
|
|
296
324
|
/** A value in words: its entry in `labels`, else the value in title case (`draft` → "Draft"). */
|
|
297
325
|
declare function valueText(labels: Readonly<Record<string, string>> | undefined, value: unknown): string;
|
|
298
326
|
/**
|
|
@@ -602,4 +630,4 @@ declare function isWorkspace(value: unknown): value is ResourceWorkspace;
|
|
|
602
630
|
*/
|
|
603
631
|
declare function defineWorkspace<C extends ResourceContract, Row extends DataRow = RowOf<C>>(view: ResourceView<C, Row>, definition: WorkspaceDefinition<C, Row>): ResourceWorkspace<C, Row>;
|
|
604
632
|
|
|
605
|
-
export { type Allowed, type ComputedColumn, type DisplayHint, type FieldNameOf, type ResolvedColumn, type ResolvedFormField, type ResolvedReadinessItem, type ResolvedViewAction, type ResolvedWorkspaceSection, type ResourceTree, type ResourceView, type ResourceWorkspace, type RowImage, RowOf, type RowPicture, type RowSummary, type TimeZoneName, type TreeNode, type TreeOptions, type TreeResult, type ViewAction, type ViewColumn, type ViewCopy, type ViewDefinition, ViewDefinitionError, type ViewField, type ViewFormItem, type ViewGuards, type ViewPreset, type ViewTimeZone, type ViewTone, Viewer, type WorkspaceDefinition, type WorkspaceFilter, type WorkspaceHeader, type WorkspaceHeaderAction, type WorkspaceHeaderOptions, type WorkspaceListSection, type WorkspaceReadinessItem, type WorkspaceSection, type WorkspaceSettingsSection, type WorkspaceSlotSection, cascadeSelection, defineView, defineWorkspace, deriveDisplay, initialExpanded, initialsOf, isWorkspace, rowPicture, scopeValues, setExpanded, treeRows, valueText };
|
|
633
|
+
export { type Allowed, type ComputedColumn, type DisplayHint, type FieldNameOf, type ResolvedColumn, type ResolvedFormField, type ResolvedReadinessItem, type ResolvedViewAction, type ResolvedWorkspaceSection, type ResourceTree, type ResourceView, type ResourceWorkspace, type RowImage, RowOf, type RowPicture, type RowSummary, type TimeZoneName, type TreeNode, type TreeOptions, type TreeResult, type ViewAction, type ViewColumn, type ViewCopy, type ViewDefinition, ViewDefinitionError, type ViewField, type ViewFormItem, type ViewGuards, type ViewPreset, type ViewTimeZone, type ViewTone, Viewer, type WorkspaceDefinition, type WorkspaceFilter, type WorkspaceHeader, type WorkspaceHeaderAction, type WorkspaceHeaderOptions, type WorkspaceListSection, type WorkspaceReadinessItem, type WorkspaceSection, type WorkspaceSettingsSection, type WorkspaceSlotSection, cascadeSelection, defineView, defineWorkspace, deriveDisplay, initialExpanded, initialsOf, isWorkspace, plural, rowPicture, scopeValues, setExpanded, singular, treeRows, valueText };
|
|
@@ -64,6 +64,19 @@ function singular(word) {
|
|
|
64
64
|
if (/(?:ss|us|is)$/.test(lower) || !lower.endsWith("s")) return word;
|
|
65
65
|
return one(last.slice(0, -1));
|
|
66
66
|
}
|
|
67
|
+
var PLURAL_OF = Object.fromEntries(
|
|
68
|
+
Object.entries(SAME_OR_IRREGULAR).map(([many, one]) => [one, many])
|
|
69
|
+
);
|
|
70
|
+
function plural(word) {
|
|
71
|
+
const last = word.split(" ").pop();
|
|
72
|
+
const head = word.slice(0, word.length - last.length);
|
|
73
|
+
const lower = last.toLowerCase();
|
|
74
|
+
const many = (s) => head + s;
|
|
75
|
+
if (PLURAL_OF[lower]) return many(PLURAL_OF[lower]);
|
|
76
|
+
if (/[^aeiou]y$/.test(lower)) return many(`${last.slice(0, -1)}ies`);
|
|
77
|
+
if (/(?:s|x|z|ch|sh)$/.test(lower)) return many(`${last}es`);
|
|
78
|
+
return many(`${last}s`);
|
|
79
|
+
}
|
|
67
80
|
var RESERVED_ACTIONS = /* @__PURE__ */ new Set(["create", "update", "delete"]);
|
|
68
81
|
var own = (record, key) => record && Object.hasOwn(record, key) ? record[key] : void 0;
|
|
69
82
|
function valueText(labels, value) {
|
|
@@ -202,7 +215,8 @@ function defineView(contract, definition = {}) {
|
|
|
202
215
|
const copy = definition.copy ?? {};
|
|
203
216
|
const base = contract.name.split(".").pop() ?? contract.name;
|
|
204
217
|
const noun = copy.noun ?? facts.noun ?? singular(base.replace(/_/g, " "));
|
|
205
|
-
const
|
|
218
|
+
const labelWords = facts.label?.toLowerCase();
|
|
219
|
+
const nounPlural = copy.nounPlural ?? facts.nounPlural ?? (copy.noun || facts.noun ? plural(noun) : labelWords && singular(labelWords) !== labelWords ? labelWords : base.replace(/_/g, " "));
|
|
206
220
|
const title = copy.title ?? facts.label ?? titleCase(nounPlural);
|
|
207
221
|
const labelField = facts.labelField ?? fields.find((f) => /^(name|title|label|full_name|display_name)$/.test(f.name))?.name;
|
|
208
222
|
const label = (name) => own(viewFields, name)?.label ?? byName.get(name)?.label ?? titleCase(name);
|
|
@@ -712,6 +726,6 @@ function defineWorkspace(view, definition) {
|
|
|
712
726
|
});
|
|
713
727
|
}
|
|
714
728
|
|
|
715
|
-
export { ViewDefinitionError, cascadeSelection, defineView, defineWorkspace, deriveDisplay, initialExpanded, initialsOf, isWorkspace, rowPicture, scopeValues, setExpanded, treeRows, valueText };
|
|
729
|
+
export { ViewDefinitionError, cascadeSelection, defineView, defineWorkspace, deriveDisplay, initialExpanded, initialsOf, isWorkspace, plural, rowPicture, scopeValues, setExpanded, singular, treeRows, valueText };
|
|
716
730
|
//# sourceMappingURL=index.js.map
|
|
717
731
|
//# sourceMappingURL=index.js.map
|