@marktiderman/genesis-core 1.13.0 → 1.14.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 (42) hide show
  1. package/README.md +45 -0
  2. package/dist/{chunk-REYTMXAA.js → chunk-3LZAZ5KB.js} +3 -3
  3. package/dist/{chunk-REYTMXAA.js.map → chunk-3LZAZ5KB.js.map} +1 -1
  4. package/dist/chunk-4VRVVN2S.js +109 -0
  5. package/dist/chunk-4VRVVN2S.js.map +1 -0
  6. package/dist/{chunk-JKZ2FVWK.js → chunk-7YHGNPPO.js} +4 -4
  7. package/dist/{chunk-JKZ2FVWK.js.map → chunk-7YHGNPPO.js.map} +1 -1
  8. package/dist/{chunk-TCL27Q5W.js → chunk-K7K6NY3C.js} +4 -113
  9. package/dist/chunk-K7K6NY3C.js.map +1 -0
  10. package/dist/chunk-OZYF55E3.js +6 -0
  11. package/dist/chunk-OZYF55E3.js.map +1 -0
  12. package/dist/chunk-PA6WJE5E.js +115 -0
  13. package/dist/chunk-PA6WJE5E.js.map +1 -0
  14. package/dist/chunk-PP3XFFQM.js +85 -0
  15. package/dist/chunk-PP3XFFQM.js.map +1 -0
  16. package/dist/{chunk-GEF5W2LO.js → chunk-YFTGLQDQ.js} +4 -4
  17. package/dist/{chunk-GEF5W2LO.js.map → chunk-YFTGLQDQ.js.map} +1 -1
  18. package/dist/chunk-ZIMQUFXD.js +154 -0
  19. package/dist/chunk-ZIMQUFXD.js.map +1 -0
  20. package/dist/errors.d.ts +69 -0
  21. package/dist/errors.js +7 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/hooks/index.d.ts +1 -1
  24. package/dist/hooks/index.js +15 -11
  25. package/dist/hooks/mutation-mode.js +2 -2
  26. package/dist/hooks/use-resource-form.js +6 -6
  27. package/dist/hooks/use-resource.js +4 -4
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.js +18 -15
  30. package/dist/provider/index.js +4 -3
  31. package/dist/resource/index.d.ts +2 -49
  32. package/dist/resource/index.js +1 -83
  33. package/dist/resource/index.js.map +1 -1
  34. package/dist/resource-view/index.d.ts +216 -17
  35. package/dist/resource-view/index.js +263 -13
  36. package/dist/resource-view/index.js.map +1 -1
  37. package/dist/status-BXRokZD9.d.ts +50 -0
  38. package/dist/{viewer-scope-0dR-_o0f.d.ts → viewer-scope-77MqxvmZ.d.ts} +51 -2
  39. package/package.json +5 -1
  40. package/dist/chunk-FARKPY6R.js +0 -66
  41. package/dist/chunk-FARKPY6R.js.map +0 -1
  42. package/dist/chunk-TCL27Q5W.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ /** Where a reported error came from. */
2
+ interface ErrorReportContext {
3
+ /**
4
+ * Which part caught it, as `package:part` (`chat:attachment-action`,
5
+ * `forms-native:draft-save`). Low-cardinality: never an id or text.
6
+ */
7
+ source: string;
8
+ /** True when the app could not go on. Default false: a package that reports has handled it. */
9
+ fatal?: boolean;
10
+ /** Low-cardinality labels (`query.key: "tasks"`), never ids, emails or text someone typed. */
11
+ tags?: Readonly<Record<string, string>>;
12
+ }
13
+ /** Where `reportError` sends errors. A throw inside it is ignored. */
14
+ type ErrorReporter = (error: unknown, context: ErrorReportContext) => void;
15
+ /** The reporter used when the app registered none: `console.warn` in development, nothing in production. */
16
+ declare const defaultErrorReporter: ErrorReporter;
17
+ /** The reporter `reportError` uses now. */
18
+ declare function getErrorReporter(): ErrorReporter;
19
+ /**
20
+ * Send every `reportError` to `reporter` (`null` puts the default back).
21
+ * Returns a function that restores the reporter that was there before.
22
+ * The native observability block calls it when it is created.
23
+ */
24
+ declare function setErrorReporter(reporter: ErrorReporter | null): () => void;
25
+ /**
26
+ * Report an error a package caught and handled. Never throws: a failing
27
+ * reporter must not take the caller (an event handler, a render) down.
28
+ * `context` may be just the source.
29
+ */
30
+ declare function reportError(error: unknown, context: ErrorReportContext | string): void;
31
+ /**
32
+ * - `offline`: the request never reached the server (no network).
33
+ * - `unauthenticated`: nobody is signed in, or the session ended.
34
+ * - `forbidden`: the server refused this user.
35
+ * - `not-found`: the record doesn't exist, or this user can't see it.
36
+ * - `conflict`: someone else changed it first, or it already exists.
37
+ * - `invalid`: the request or a value in it was rejected.
38
+ * - `unexpected`: anything else (a bug, a server error).
39
+ */
40
+ type ErrorKind = "offline" | "unauthenticated" | "forbidden" | "not-found" | "conflict" | "invalid" | "unexpected";
41
+ /** The sentence shown for each kind. Override any of them with `classifyError(e, { messages })`. */
42
+ type ErrorMessages = Readonly<Record<ErrorKind, string>>;
43
+ /** The English catalogue. Plain words, never the store's text. */
44
+ declare const errorMessages: ErrorMessages;
45
+ interface ClassifiedError {
46
+ kind: ErrorKind;
47
+ /** Safe to show: from the messages catalogue, never the error's own text. */
48
+ message: string;
49
+ /** Worth reporting to a crash tracker: a bug or a server failure, not something the user or the network caused. */
50
+ report: boolean;
51
+ }
52
+ interface ClassifyErrorOptions {
53
+ /** Reworded or translated sentences; what you leave out stays English. */
54
+ messages?: Partial<ErrorMessages>;
55
+ /** True when the device knows it is offline (TanStack's `onlineManager`, NetInfo). */
56
+ isOffline?: () => boolean;
57
+ }
58
+ /**
59
+ * What kind of error this is, a sentence that is safe to show, and whether it
60
+ * is worth reporting. Understands the provider's `DataWriteError` and
61
+ * `DataReadError`, Postgres and PostgREST codes, HTTP statuses, Supabase's
62
+ * auth and fetch errors, and each runtime's "network request failed".
63
+ *
64
+ * Use it for a toast (`toast.error(classifyError(e).message)`) and to decide
65
+ * whether to report (`if (classifyError(e).report) reportError(e, …)`).
66
+ */
67
+ declare function classifyError(error: unknown, options?: ClassifyErrorOptions): ClassifiedError;
68
+
69
+ export { type ClassifiedError, type ClassifyErrorOptions, type ErrorKind, type ErrorMessages, type ErrorReportContext, type ErrorReporter, classifyError, defaultErrorReporter, errorMessages, getErrorReporter, reportError, setErrorReporter };
package/dist/errors.js ADDED
@@ -0,0 +1,7 @@
1
+ export { classifyError, defaultErrorReporter, errorMessages, getErrorReporter, reportError, setErrorReporter } from './chunk-ZIMQUFXD.js';
2
+ import './chunk-PA6WJE5E.js';
3
+ import './chunk-HUNGCTRA.js';
4
+ import './chunk-RYEXWQFD.js';
5
+ import './chunk-LG6TUBVM.js';
6
+ //# sourceMappingURL=errors.js.map
7
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"errors.js"}
@@ -5,7 +5,7 @@ export { useCapabilities } from './use-capabilities.js';
5
5
  export { UseWriteOptions, UseWriteReturn, WRITE_FAILED, useWrite } from './use-write.js';
6
6
  export { UseDraftReturn, useDraft } from './use-draft.js';
7
7
  export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftAdoption, DraftController, DraftOptions, DraftSeed, DraftState, DraftStatus, DraftValue, isNetworkFailure, stableJson } from './draft-controller.js';
8
- export { R as ResourceScope, V as ViewerContext, a as ViewerScope, b as ViewerScopeProps, c as clearViewerCache, u as useOptionalViewerScope, d as useViewerScope } from '../viewer-scope-0dR-_o0f.js';
8
+ 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, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from '../viewer-scope-77MqxvmZ.js';
9
9
  export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, LiveOptions } from './use-live.js';
10
10
  export { UseResourceFormOptions, UseResourceFormReturn, buildArrayItemDefaults, useResourceForm } from './use-resource-form.js';
11
11
  export { UseWizardReturn, WizardStep, useWizard } from './use-wizard.js';
@@ -1,23 +1,27 @@
1
- export { ViewerScope, clearViewerCache, useOptionalViewerScope, useViewerScope } from '../chunk-FARKPY6R.js';
2
- export { buildArrayItemDefaults, useResourceForm } from '../chunk-GEF5W2LO.js';
1
+ export { ViewerScope, clearViewerCache, useOptionalViewerScope, useViewer, useViewerScope } from '../chunk-4VRVVN2S.js';
2
+ export { NO_VIEWER } from '../chunk-OZYF55E3.js';
3
+ export { useInfiniteResource } from '../chunk-UGGMJUFQ.js';
4
+ export { buildArrayItemDefaults, useResourceForm } from '../chunk-YFTGLQDQ.js';
3
5
  export { useOne } from '../chunk-RF6YVWHX.js';
4
- export { useResource } from '../chunk-JKZ2FVWK.js';
6
+ export { useResource } from '../chunk-7YHGNPPO.js';
7
+ export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from '../chunk-UV3ROHQA.js';
5
8
  export { DEFAULT_UNSAVED_CHANGES_MESSAGE, useUnsavedChangesGuard } from '../chunk-XQO4OH2N.js';
6
9
  export { useWizard } from '../chunk-7KOLYF27.js';
7
10
  export { WRITE_FAILED, useWrite } from '../chunk-52T2EYXH.js';
8
- export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from '../chunk-REYTMXAA.js';
9
- import '../chunk-7NUL32W7.js';
10
- export { useCapabilities } from '../chunk-BQOJX67X.js';
11
- export { useDraft } from '../chunk-DF2UWEEB.js';
12
- export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftController, isNetworkFailure, stableJson } from '../chunk-HBAPYA5K.js';
13
- import '../chunk-LG6TUBVM.js';
14
- export { useInfiniteResource } from '../chunk-UGGMJUFQ.js';
15
- export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from '../chunk-UV3ROHQA.js';
16
11
  import '../chunk-AUVKRXRC.js';
12
+ export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from '../chunk-3LZAZ5KB.js';
17
13
  import '../chunk-OYIUIW7C.js';
14
+ import '../chunk-7NUL32W7.js';
15
+ export { useCapabilities } from '../chunk-BQOJX67X.js';
18
16
  import '../chunk-GGSXSI6Z.js';
19
17
  import '../chunk-ZYJUEJ4Z.js';
18
+ export { useDraft } from '../chunk-DF2UWEEB.js';
19
+ export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftController, isNetworkFailure, stableJson } from '../chunk-HBAPYA5K.js';
20
20
  import '../chunk-3B4IFDMK.js';
21
+ import '../chunk-ZIMQUFXD.js';
22
+ import '../chunk-PA6WJE5E.js';
23
+ import '../chunk-HUNGCTRA.js';
21
24
  import '../chunk-RYEXWQFD.js';
25
+ import '../chunk-LG6TUBVM.js';
22
26
  //# sourceMappingURL=index.js.map
23
27
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
- export { DEFAULT_UNDO_DELAY_MS, DROPPED_WRITE_MESSAGE, cachedRecord, dropPendingWrites, executeWrite, flushPendingWrites, invalidateResource, pendingWriteCount, providerServesUndo, sameValue } from '../chunk-REYTMXAA.js';
2
- import '../chunk-BQOJX67X.js';
1
+ export { DEFAULT_UNDO_DELAY_MS, DROPPED_WRITE_MESSAGE, cachedRecord, dropPendingWrites, executeWrite, flushPendingWrites, invalidateResource, pendingWriteCount, providerServesUndo, sameValue } from '../chunk-3LZAZ5KB.js';
3
2
  import '../chunk-OYIUIW7C.js';
3
+ import '../chunk-BQOJX67X.js';
4
4
  import '../chunk-GGSXSI6Z.js';
5
5
  import '../chunk-ZYJUEJ4Z.js';
6
6
  //# sourceMappingURL=mutation-mode.js.map
@@ -1,15 +1,15 @@
1
- export { buildArrayItemDefaults, useResourceForm } from '../chunk-GEF5W2LO.js';
1
+ export { buildArrayItemDefaults, useResourceForm } from '../chunk-YFTGLQDQ.js';
2
2
  import '../chunk-RF6YVWHX.js';
3
- import '../chunk-XQO4OH2N.js';
4
- import '../chunk-REYTMXAA.js';
5
- import '../chunk-7NUL32W7.js';
6
- import '../chunk-BQOJX67X.js';
7
- import '../chunk-LG6TUBVM.js';
8
3
  import '../chunk-UV3ROHQA.js';
4
+ import '../chunk-XQO4OH2N.js';
9
5
  import '../chunk-AUVKRXRC.js';
6
+ import '../chunk-3LZAZ5KB.js';
10
7
  import '../chunk-OYIUIW7C.js';
8
+ import '../chunk-7NUL32W7.js';
9
+ import '../chunk-BQOJX67X.js';
11
10
  import '../chunk-GGSXSI6Z.js';
12
11
  import '../chunk-ZYJUEJ4Z.js';
13
12
  import '../chunk-RYEXWQFD.js';
13
+ import '../chunk-LG6TUBVM.js';
14
14
  //# sourceMappingURL=use-resource-form.js.map
15
15
  //# sourceMappingURL=use-resource-form.js.map
@@ -1,10 +1,10 @@
1
- export { useResource } from '../chunk-JKZ2FVWK.js';
2
- import '../chunk-REYTMXAA.js';
3
- import '../chunk-7NUL32W7.js';
4
- import '../chunk-BQOJX67X.js';
1
+ export { useResource } from '../chunk-7YHGNPPO.js';
5
2
  import '../chunk-UV3ROHQA.js';
6
3
  import '../chunk-AUVKRXRC.js';
4
+ import '../chunk-3LZAZ5KB.js';
7
5
  import '../chunk-OYIUIW7C.js';
6
+ import '../chunk-7NUL32W7.js';
7
+ import '../chunk-BQOJX67X.js';
8
8
  import '../chunk-GGSXSI6Z.js';
9
9
  import '../chunk-ZYJUEJ4Z.js';
10
10
  //# sourceMappingURL=use-resource.js.map
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export { useCapabilities } from './hooks/use-capabilities.js';
12
12
  export { UseWriteOptions, UseWriteReturn, WRITE_FAILED, useWrite } from './hooks/use-write.js';
13
13
  export { UseDraftReturn, useDraft } from './hooks/use-draft.js';
14
14
  export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftAdoption, DraftController, DraftOptions, DraftSeed, DraftState, DraftStatus, DraftValue, isNetworkFailure, stableJson } from './hooks/draft-controller.js';
15
- export { R as ResourceScope, V as ViewerContext, a as ViewerScope, b as ViewerScopeProps, c as clearViewerCache, u as useOptionalViewerScope, d as useViewerScope } from './viewer-scope-0dR-_o0f.js';
15
+ 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, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from './viewer-scope-77MqxvmZ.js';
16
16
  export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, LiveOptions } from './hooks/use-live.js';
17
17
  export { UseResourceFormOptions, UseResourceFormReturn, buildArrayItemDefaults, useResourceForm } from './hooks/use-resource-form.js';
18
18
  export { UseWizardReturn, WizardStep, useWizard } from './hooks/use-wizard.js';
@@ -23,6 +23,7 @@ export { A as AuditEntry, D as DataRow, a as FieldPermissions, b as FieldReferen
23
23
  export { decodeRecordKey, encodeRecordKey, keyFields } from './schema/index.js';
24
24
  import { Query } from '@tanstack/react-query';
25
25
  export { isSafeUrl, normalizeLinkUrl } from './urls.js';
26
+ export { ClassifiedError, ClassifyErrorOptions, ErrorKind, ErrorMessages, ErrorReportContext, ErrorReporter, classifyError, defaultErrorReporter, errorMessages, getErrorReporter, reportError, setErrorReporter } from './errors.js';
26
27
  export { titleCase } from './utils.js';
27
28
  import 'react';
28
29
  import './dates.js';
package/dist/index.js CHANGED
@@ -1,30 +1,33 @@
1
- import './chunk-XCX2TRBL.js';
1
+ export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from './chunk-K7K6NY3C.js';
2
2
  export { defineResource } from './chunk-7FVTGKTX.js';
3
3
  export { decodeRecordKey, encodeRecordKey, keyFields } from './chunk-KV2HW4G4.js';
4
- export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from './chunk-TCL27Q5W.js';
5
- export { DataReadError, isDataReadError, readFailureMessage } from './chunk-HUNGCTRA.js';
6
- export { ViewerScope, clearViewerCache, useOptionalViewerScope, useViewerScope } from './chunk-FARKPY6R.js';
7
- export { buildArrayItemDefaults, useResourceForm } from './chunk-GEF5W2LO.js';
4
+ import './chunk-XCX2TRBL.js';
5
+ export { ViewerScope, clearViewerCache, useOptionalViewerScope, useViewer, useViewerScope } from './chunk-4VRVVN2S.js';
6
+ export { NO_VIEWER } from './chunk-OZYF55E3.js';
7
+ export { useInfiniteResource } from './chunk-UGGMJUFQ.js';
8
+ export { buildArrayItemDefaults, useResourceForm } from './chunk-YFTGLQDQ.js';
8
9
  export { useOne } from './chunk-RF6YVWHX.js';
9
- export { useResource } from './chunk-JKZ2FVWK.js';
10
+ export { useResource } from './chunk-7YHGNPPO.js';
11
+ export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from './chunk-UV3ROHQA.js';
10
12
  export { DEFAULT_UNSAVED_CHANGES_MESSAGE, useUnsavedChangesGuard } from './chunk-XQO4OH2N.js';
11
13
  export { useWizard } from './chunk-7KOLYF27.js';
12
14
  export { WRITE_FAILED, useWrite } from './chunk-52T2EYXH.js';
13
- export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './chunk-REYTMXAA.js';
14
- import './chunk-7NUL32W7.js';
15
- export { useCapabilities } from './chunk-BQOJX67X.js';
16
- export { useDraft } from './chunk-DF2UWEEB.js';
17
- export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftController, isNetworkFailure, stableJson } from './chunk-HBAPYA5K.js';
18
- export { DataWriteError, isDataWriteError } from './chunk-LG6TUBVM.js';
19
- export { useInfiniteResource } from './chunk-UGGMJUFQ.js';
20
- export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from './chunk-UV3ROHQA.js';
21
15
  import './chunk-AUVKRXRC.js';
16
+ export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './chunk-3LZAZ5KB.js';
22
17
  export { defineQueryKeys, resourceKeys } from './chunk-OYIUIW7C.js';
18
+ import './chunk-7NUL32W7.js';
19
+ export { useCapabilities } from './chunk-BQOJX67X.js';
23
20
  export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from './chunk-GGSXSI6Z.js';
24
21
  export { createLocalStorageAdapter, createMemoryStorageAdapter, createNoopStorageAdapter } from './chunk-ZYJUEJ4Z.js';
22
+ export { useDraft } from './chunk-DF2UWEEB.js';
23
+ export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftController, isNetworkFailure, stableJson } from './chunk-HBAPYA5K.js';
25
24
  import './chunk-3B4IFDMK.js';
25
+ export { classifyError, defaultErrorReporter, errorMessages, getErrorReporter, reportError, setErrorReporter } from './chunk-ZIMQUFXD.js';
26
+ export { fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from './chunk-PA6WJE5E.js';
27
+ export { DataReadError, isDataReadError, readFailureMessage } from './chunk-HUNGCTRA.js';
28
+ export { titleCase } from './chunk-RYEXWQFD.js';
29
+ export { DataWriteError, isDataWriteError } from './chunk-LG6TUBVM.js';
26
30
  import './chunk-65SXNHWE.js';
27
31
  export { isSafeUrl, normalizeLinkUrl } from './chunk-YDDPFSQ6.js';
28
- export { titleCase } from './chunk-RYEXWQFD.js';
29
32
  //# sourceMappingURL=index.js.map
30
33
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,9 @@
1
- export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from '../chunk-TCL27Q5W.js';
2
- export { DataReadError, isDataReadError, readFailureMessage } from '../chunk-HUNGCTRA.js';
3
- export { DataWriteError, isDataWriteError } from '../chunk-LG6TUBVM.js';
1
+ export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from '../chunk-K7K6NY3C.js';
4
2
  export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from '../chunk-GGSXSI6Z.js';
5
3
  import '../chunk-ZYJUEJ4Z.js';
4
+ export { fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from '../chunk-PA6WJE5E.js';
5
+ export { DataReadError, isDataReadError, readFailureMessage } from '../chunk-HUNGCTRA.js';
6
6
  import '../chunk-RYEXWQFD.js';
7
+ export { DataWriteError, isDataWriteError } from '../chunk-LG6TUBVM.js';
7
8
  //# sourceMappingURL=index.js.map
8
9
  //# sourceMappingURL=index.js.map
@@ -1,51 +1,4 @@
1
- /** Where the host's draft saving stands. */
2
- type SaveState = "saved" | "saving" | "unsaved" | "failed" | "stopped" | "conflict";
3
- declare const SAVE_STATE_LABEL: Record<SaveState, string>;
4
- /** A chip's colour: the tinted, AA-safe Genesis badge tones. */
5
- type ChipTone = "success" | "warning" | "danger" | "info" | "muted";
6
- /** Whether something can be published, from an editor's checks. */
7
- interface Readiness {
8
- state: "ready" | "problems" | "warnings" | "empty" | "pending";
9
- /** Problems or warnings to look at (0 when ready, empty or pending). */
10
- count: number;
11
- }
12
- /** One of an editor's findings, as readinessOf reads it. */
13
- interface ReadinessFinding {
14
- level: "error" | "warning" | "info";
15
- code?: string | undefined;
16
- }
17
- interface ReadinessOptions {
18
- /** Errors are held back while something new is being written: "pending", not "problems". */
19
- pending?: boolean | undefined;
20
- /**
21
- * The finding code that means "nothing to publish yet" (for example a form builder's
22
- * `no-questions`): it makes the result "empty", not broken. None by default.
23
- */
24
- emptyCode?: string | undefined;
25
- }
26
- /**
27
- * Readiness from an editor's findings (any list of `{ level, code? }`): errors block
28
- * publishing, warnings ask for a look. One pass over the findings.
29
- */
30
- declare function readinessOf(findings: readonly ReadinessFinding[], options?: ReadinessOptions): Readiness;
31
- /** The readiness chip's words, each optional; the defaults are resource-neutral. */
32
- interface ReadinessLabels {
33
- /** Default "Ready to publish". */
34
- ready?: string | undefined;
35
- /** When there is nothing yet. Default "Nothing to publish yet"; a form says "Add a question". */
36
- empty?: string | undefined;
37
- /** Default "In progress". */
38
- pending?: string | undefined;
39
- /** Default "1 problem to fix" / "3 problems to fix". */
40
- problems?: ((count: number) => string) | undefined;
41
- /** Default "2 to check". */
42
- warnings?: ((count: number) => string) | undefined;
43
- }
44
- /** The readiness chip's label and tone. */
45
- declare function readinessChip(readiness: Readiness, labels?: ReadinessLabels): {
46
- label: string;
47
- tone: ChipTone;
48
- };
1
+ export { C as ChipTone, R as Readiness, a as ReadinessFinding, b as ReadinessLabels, c as ReadinessOptions, S as SAVE_STATE_LABEL, d as SaveState, r as readinessChip, e as readinessOf } from '../status-BXRokZD9.js';
49
2
 
50
3
  /** A day (YYYY-MM-DD) in words, given today on the same clock: "Today", "Yesterday", "Oct 21", "Oct 21, 2025". */
51
4
  declare function dayLabel(day: string, today?: string): string;
@@ -83,4 +36,4 @@ interface HeadlineNumber {
83
36
  tone?: HeadlineTone | undefined;
84
37
  }
85
38
 
86
- export { type ChipTone, type HeadlineNumber, type HeadlineTone, type PrefillChoice, type Readiness, type ReadinessFinding, type ReadinessLabels, type ReadinessOptions, SAVE_STATE_LABEL, type SaveState, dayLabel, embedSnippet, prefilledUrl, readinessChip, readinessOf };
39
+ export { type HeadlineNumber, type HeadlineTone, type PrefillChoice, dayLabel, embedSnippet, prefilledUrl };
@@ -1,85 +1,3 @@
1
- // src/resource/status.ts
2
- var SAVE_STATE_LABEL = {
3
- saved: "Changes saved",
4
- saving: "Saving\u2026",
5
- unsaved: "Unsaved changes",
6
- failed: "Couldn't save; trying again",
7
- stopped: "Couldn't save",
8
- conflict: "Changed elsewhere; reload"
9
- };
10
- function readinessOf(findings, options = {}) {
11
- const { emptyCode, pending } = options;
12
- let errors = 0;
13
- let warnings = 0;
14
- for (const f of findings) {
15
- if (emptyCode !== void 0 && f.code === emptyCode) return { state: "empty", count: 0 };
16
- if (f.level === "error") errors++;
17
- else if (f.level === "warning") warnings++;
18
- }
19
- if (errors) return { state: "problems", count: errors };
20
- if (pending) return { state: "pending", count: 0 };
21
- if (warnings) return { state: "warnings", count: warnings };
22
- return { state: "ready", count: 0 };
23
- }
24
- function readinessChip(readiness, labels = {}) {
25
- switch (readiness.state) {
26
- case "ready":
27
- return { label: labels.ready ?? "Ready to publish", tone: "success" };
28
- case "empty":
29
- return { label: labels.empty ?? "Nothing to publish yet", tone: "muted" };
30
- case "pending":
31
- return { label: labels.pending ?? "In progress", tone: "muted" };
32
- case "problems":
33
- return {
34
- label: labels.problems?.(readiness.count) ?? `${readiness.count} ${readiness.count === 1 ? "problem" : "problems"} to fix`,
35
- tone: "danger"
36
- };
37
- case "warnings":
38
- return { label: labels.warnings?.(readiness.count) ?? `${readiness.count} to check`, tone: "warning" };
39
- }
40
- }
41
-
42
- // src/resource/days.ts
43
- var MONTH_DAY = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", timeZone: "UTC" });
44
- var MONTH_DAY_YEAR = new Intl.DateTimeFormat("en-US", {
45
- month: "short",
46
- day: "numeric",
47
- year: "numeric",
48
- timeZone: "UTC"
49
- });
50
- function dayLabel(day, today) {
51
- const t = Date.parse(`${day}T00:00:00Z`);
52
- if (Number.isNaN(t)) return day;
53
- if (today) {
54
- const diff = Math.round((Date.parse(`${today}T00:00:00Z`) - t) / 864e5);
55
- if (diff === 0) return "Today";
56
- if (diff === 1) return "Yesterday";
57
- if (day.slice(0, 4) !== today.slice(0, 4)) return MONTH_DAY_YEAR.format(t);
58
- }
59
- return MONTH_DAY.format(t);
60
- }
61
-
62
- // src/resource/share.ts
63
- var RELATIVE_BASE = "http://relative.invalid";
64
- function prefilledUrl(url, values) {
65
- let absolute = true;
66
- let u;
67
- try {
68
- u = new URL(url);
69
- } catch {
70
- absolute = false;
71
- u = new URL(url, RELATIVE_BASE);
72
- }
73
- for (const [k, v] of Object.entries(values)) if (v) u.searchParams.set(k, v);
74
- if (absolute) return u.toString();
75
- const path = url.startsWith("/") ? u.pathname : u.pathname.replace(/^\//, "");
76
- return `${path}${u.search}${u.hash}`;
77
- }
78
- var attr = (s) => s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
79
- function embedSnippet(url, title) {
80
- return `<iframe src="${attr(url)}" title="${attr(title)}" width="100%" height="720" style="border:0;max-width:100%" loading="lazy"></iframe>`;
81
- }
82
-
83
- export { SAVE_STATE_LABEL, dayLabel, embedSnippet, prefilledUrl, readinessChip, readinessOf };
1
+ export { SAVE_STATE_LABEL, dayLabel, embedSnippet, prefilledUrl, readinessChip, readinessOf } from '../chunk-PP3XFFQM.js';
84
2
  //# sourceMappingURL=index.js.map
85
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resource/status.ts","../../src/resource/days.ts","../../src/resource/share.ts"],"names":[],"mappings":";AAOO,IAAM,gBAAA,GAA8C;AAAA,EACzD,KAAA,EAAO,eAAA;AAAA,EACP,MAAA,EAAQ,cAAA;AAAA,EACR,OAAA,EAAS,iBAAA;AAAA,EACT,MAAA,EAAQ,6BAAA;AAAA,EACR,OAAA,EAAS,eAAA;AAAA,EACT,QAAA,EAAU;AACZ;AAgCO,SAAS,WAAA,CACd,QAAA,EACA,OAAA,GAA4B,EAAC,EAClB;AACX,EAAA,MAAM,EAAE,SAAA,EAAW,OAAA,EAAQ,GAAI,OAAA;AAC/B,EAAA,IAAI,MAAA,GAAS,CAAA;AACb,EAAA,IAAI,QAAA,GAAW,CAAA;AACf,EAAA,KAAA,MAAW,KAAK,QAAA,EAAU;AACxB,IAAA,IAAI,SAAA,KAAc,MAAA,IAAa,CAAA,CAAE,IAAA,KAAS,SAAA,SAAkB,EAAE,KAAA,EAAO,OAAA,EAAS,KAAA,EAAO,CAAA,EAAE;AACvF,IAAA,IAAI,CAAA,CAAE,UAAU,OAAA,EAAS,MAAA,EAAA;AAAA,SAAA,IAChB,CAAA,CAAE,UAAU,SAAA,EAAW,QAAA,EAAA;AAAA,EAClC;AACA,EAAA,IAAI,QAAQ,OAAO,EAAE,KAAA,EAAO,UAAA,EAAY,OAAO,MAAA,EAAO;AACtD,EAAA,IAAI,SAAS,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,OAAO,CAAA,EAAE;AACjD,EAAA,IAAI,UAAU,OAAO,EAAE,KAAA,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AAA,EAAG,CAAC,CAAA,IAAK,OAAO,OAAA,CAAQ,MAAM,CAAA,EAAG,IAAI,CAAA,EAAG,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,GAAG,CAAC,CAAA;AAC3E,EAAA,IAAI,QAAA,EAAU,OAAO,CAAA,CAAE,QAAA,EAAS;AAChC,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,UAAA,CAAW,GAAG,CAAA,GAAI,CAAA,CAAE,QAAA,GAAW,CAAA,CAAE,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC5E,EAAA,OAAO,GAAG,IAAI,CAAA,EAAG,EAAE,MAAM,CAAA,EAAG,EAAE,IAAI,CAAA,CAAA;AACpC;AAEA,IAAM,OAAO,CAAC,CAAA,KACZ,EAAE,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,QAAQ,EAAE,OAAA,CAAQ,IAAA,EAAM,MAAM,CAAA,CAAE,OAAA,CAAQ,MAAM,MAAM,CAAA;AAGtF,SAAS,YAAA,CAAa,KAAa,KAAA,EAAuB;AAC/D,EAAA,OAAO,gBAAgB,IAAA,CAAK,GAAG,CAAC,CAAA,SAAA,EAAY,IAAA,CAAK,KAAK,CAAC,CAAA,oFAAA,CAAA;AACzD","file":"index.js","sourcesContent":["// Words for a resource page's chips (save state, readiness). Pure: no React, safe on a\n// server. Not about any one kind of resource: forms, courses, lessons and worksheets use\n// the same page pattern.\n\n/** Where the host's draft saving stands. */\nexport type SaveState = \"saved\" | \"saving\" | \"unsaved\" | \"failed\" | \"stopped\" | \"conflict\";\n\nexport const SAVE_STATE_LABEL: Record<SaveState, string> = {\n saved: \"Changes saved\",\n saving: \"Saving…\",\n unsaved: \"Unsaved changes\",\n failed: \"Couldn't save; trying again\",\n stopped: \"Couldn't save\",\n conflict: \"Changed elsewhere; reload\",\n};\n\n/** A chip's colour: the tinted, AA-safe Genesis badge tones. */\nexport type ChipTone = \"success\" | \"warning\" | \"danger\" | \"info\" | \"muted\";\n\n/** Whether something can be published, from an editor's checks. */\nexport interface Readiness {\n state: \"ready\" | \"problems\" | \"warnings\" | \"empty\" | \"pending\";\n /** Problems or warnings to look at (0 when ready, empty or pending). */\n count: number;\n}\n\n/** One of an editor's findings, as readinessOf reads it. */\nexport interface ReadinessFinding {\n level: \"error\" | \"warning\" | \"info\";\n code?: string | undefined;\n}\n\nexport interface ReadinessOptions {\n /** Errors are held back while something new is being written: \"pending\", not \"problems\". */\n pending?: boolean | undefined;\n /**\n * The finding code that means \"nothing to publish yet\" (for example a form builder's\n * `no-questions`): it makes the result \"empty\", not broken. None by default.\n */\n emptyCode?: string | undefined;\n}\n\n/**\n * Readiness from an editor's findings (any list of `{ level, code? }`): errors block\n * publishing, warnings ask for a look. One pass over the findings.\n */\nexport function readinessOf(\n findings: readonly ReadinessFinding[],\n options: ReadinessOptions = {},\n): Readiness {\n const { emptyCode, pending } = options;\n let errors = 0;\n let warnings = 0;\n for (const f of findings) {\n if (emptyCode !== undefined && f.code === emptyCode) return { state: \"empty\", count: 0 };\n if (f.level === \"error\") errors++;\n else if (f.level === \"warning\") warnings++;\n }\n if (errors) return { state: \"problems\", count: errors };\n if (pending) return { state: \"pending\", count: 0 };\n if (warnings) return { state: \"warnings\", count: warnings };\n return { state: \"ready\", count: 0 };\n}\n\n/** The readiness chip's words, each optional; the defaults are resource-neutral. */\nexport interface ReadinessLabels {\n /** Default \"Ready to publish\". */\n ready?: string | undefined;\n /** When there is nothing yet. Default \"Nothing to publish yet\"; a form says \"Add a question\". */\n empty?: string | undefined;\n /** Default \"In progress\". */\n pending?: string | undefined;\n /** Default \"1 problem to fix\" / \"3 problems to fix\". */\n problems?: ((count: number) => string) | undefined;\n /** Default \"2 to check\". */\n warnings?: ((count: number) => string) | undefined;\n}\n\n/** The readiness chip's label and tone. */\nexport function readinessChip(\n readiness: Readiness,\n labels: ReadinessLabels = {},\n): { label: string; tone: ChipTone } {\n switch (readiness.state) {\n case \"ready\":\n return { label: labels.ready ?? \"Ready to publish\", tone: \"success\" };\n case \"empty\":\n return { label: labels.empty ?? \"Nothing to publish yet\", tone: \"muted\" };\n case \"pending\":\n return { label: labels.pending ?? \"In progress\", tone: \"muted\" };\n case \"problems\":\n return {\n label:\n labels.problems?.(readiness.count) ??\n `${readiness.count} ${readiness.count === 1 ? \"problem\" : \"problems\"} to fix`,\n tone: \"danger\",\n };\n case \"warnings\":\n return { label: labels.warnings?.(readiness.count) ?? `${readiness.count} to check`, tone: \"warning\" };\n }\n}\n","// A day (YYYY-MM-DD) in plain words. Pure.\n\nconst MONTH_DAY = new Intl.DateTimeFormat(\"en-US\", { month: \"short\", day: \"numeric\", timeZone: \"UTC\" });\nconst MONTH_DAY_YEAR = new Intl.DateTimeFormat(\"en-US\", {\n month: \"short\",\n day: \"numeric\",\n year: \"numeric\",\n timeZone: \"UTC\",\n});\n\n/** A day (YYYY-MM-DD) in words, given today on the same clock: \"Today\", \"Yesterday\", \"Oct 21\", \"Oct 21, 2025\". */\nexport function dayLabel(day: string, today?: string): string {\n const t = Date.parse(`${day}T00:00:00Z`);\n if (Number.isNaN(t)) return day;\n if (today) {\n const diff = Math.round((Date.parse(`${today}T00:00:00Z`) - t) / 86_400_000);\n if (diff === 0) return \"Today\";\n if (diff === 1) return \"Yesterday\";\n if (day.slice(0, 4) !== today.slice(0, 4)) return MONTH_DAY_YEAR.format(t);\n }\n return MONTH_DAY.format(t);\n}\n","// Sharing a published page (ShareDialog): prefilled links and the embed snippet. Pure.\n\n/** One search param a prefilled link may set, and the values staff pick from. */\nexport interface PrefillChoice {\n key: string;\n /** The picker's accessible name, e.g. \"Location\". */\n label: string;\n /** The picker's \"leave it out\" choice, e.g. \"Any location\". */\n anyLabel: string;\n options: readonly { value: string; label: string }[];\n}\n\n// Resolves a relative link without inventing an origin for it.\nconst RELATIVE_BASE = \"http://relative.invalid\";\n\n/**\n * `url` with `values` set as search params (empty values left out), keeping what it has.\n * An absolute link stays absolute; a relative one (`/f/a?x=1`) stays relative, so it never\n * throws while a page is still working out its origin.\n */\nexport function prefilledUrl(url: string, values: Record<string, string | undefined>): string {\n let absolute = true;\n let u: URL;\n try {\n u = new URL(url);\n } catch {\n absolute = false;\n u = new URL(url, RELATIVE_BASE);\n }\n for (const [k, v] of Object.entries(values)) if (v) u.searchParams.set(k, v);\n if (absolute) return u.toString();\n const path = url.startsWith(\"/\") ? u.pathname : u.pathname.replace(/^\\//, \"\");\n return `${path}${u.search}${u.hash}`;\n}\n\nconst attr = (s: string) =>\n s.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\").replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\");\n\n/** An `<iframe>` that shows the page on another website, full width. */\nexport function embedSnippet(url: string, title: string): string {\n return `<iframe src=\"${attr(url)}\" title=\"${attr(title)}\" width=\"100%\" height=\"720\" style=\"border:0;max-width:100%\" loading=\"lazy\"></iframe>`;\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}