@chelone/core 0.6.0 → 0.7.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/assistant/assistant-session.d.ts +6 -0
- package/dist/assistant/assistant-session.js +204 -181
- package/dist/assistant/echo-transport.js +26 -29
- package/dist/assistant/http-transport.d.ts +10 -0
- package/dist/assistant/http-transport.js +98 -0
- package/dist/assistant/types.d.ts +1 -7
- package/dist/auth/access-control.d.ts +13 -5
- package/dist/auth/access-control.js +25 -21
- package/dist/auth/auth-options.d.ts +21 -17
- package/dist/auth/auth-options.js +80 -48
- package/dist/auth/permission-matrix.d.ts +12 -0
- package/dist/auth/permission-matrix.js +67 -0
- package/dist/auth/types.d.ts +14 -4
- package/dist/block-editor/block-document.d.ts +60 -0
- package/dist/block-editor/block-document.js +143 -0
- package/dist/block-editor/data-blocks.d.ts +63 -0
- package/dist/block-editor/data-blocks.js +117 -0
- package/dist/chart/chart-data.js +46 -44
- package/dist/command-menu/hotkey.js +58 -47
- package/dist/command-menu/recents.js +8 -11
- package/dist/command-menu/registry.d.ts +9 -5
- package/dist/command-menu/registry.js +36 -46
- package/dist/controller/calendar-dates.js +82 -113
- package/dist/controller/calendar-events.js +93 -88
- package/dist/controller/client-list-controller.d.ts +2 -2
- package/dist/controller/client-list-controller.js +251 -254
- package/dist/controller/data-table-columns.d.ts +2 -0
- package/dist/controller/data-table-columns.js +50 -56
- package/dist/controller/deep-equal.d.ts +1 -0
- package/dist/controller/deep-equal.js +14 -0
- package/dist/controller/filter-toggle.js +36 -44
- package/dist/controller/in-place-editor.d.ts +42 -0
- package/dist/controller/in-place-editor.js +42 -0
- package/dist/controller/infinite-list-controller.js +219 -189
- package/dist/controller/inspector.d.ts +49 -0
- package/dist/controller/inspector.js +64 -0
- package/dist/controller/job-monitor.d.ts +3 -4
- package/dist/controller/job-monitor.js +37 -47
- package/dist/controller/kanban-board.d.ts +2 -3
- package/dist/controller/kanban-board.js +43 -24
- package/dist/controller/list-controller.d.ts +5 -5
- package/dist/controller/list-controller.js +444 -400
- package/dist/controller/list-params.js +96 -87
- package/dist/controller/pivot-grid.js +89 -95
- package/dist/controller/prev-next.d.ts +2 -2
- package/dist/controller/prev-next.js +74 -54
- package/dist/controller/record-controllers.d.ts +14 -6
- package/dist/controller/record-controllers.js +288 -257
- package/dist/controller/record-diff.d.ts +21 -0
- package/dist/controller/record-diff.js +50 -0
- package/dist/controller/record-timeline.js +42 -30
- package/dist/controller/record-tree.js +57 -47
- package/dist/controller/record-workflow.d.ts +38 -16
- package/dist/controller/record-workflow.js +85 -64
- package/dist/controller/reference-many-controller.js +198 -192
- package/dist/controller/reference-one-controller.d.ts +1 -1
- package/dist/controller/reference-one-controller.js +63 -56
- package/dist/controller/saved-queries.js +104 -91
- package/dist/controller/translate-fallback.js +10 -6
- package/dist/csv/export.d.ts +2 -1
- package/dist/csv/export.js +43 -40
- package/dist/csv/import-controller.js +185 -169
- package/dist/csv/match-headers.js +29 -22
- package/dist/csv/parse-with.js +60 -54
- package/dist/csv/run-import.js +69 -72
- package/dist/csv/validate-rows.d.ts +1 -1
- package/dist/csv/validate-rows.js +65 -52
- package/dist/data/cache-ops.d.ts +5 -4
- package/dist/data/cache-ops.js +208 -188
- package/dist/data/combine-data-providers.js +25 -23
- package/dist/data/data-provider-log.d.ts +45 -0
- package/dist/data/data-provider-log.js +93 -0
- package/dist/data/errors.js +14 -10
- package/dist/data/fake-provider.d.ts +6 -3
- package/dist/data/fake-provider.js +129 -114
- package/dist/data/fetch-utils.js +61 -44
- package/dist/data/filter-branch.d.ts +5 -0
- package/dist/data/filter-branch.js +10 -0
- package/dist/data/get-many-aggregate.js +84 -76
- package/dist/data/http-error.js +17 -12
- package/dist/data/keys.js +50 -36
- package/dist/data/mutation-options.d.ts +14 -9
- package/dist/data/mutation-options.js +93 -109
- package/dist/data/query-options.js +73 -68
- package/dist/data/remove-empty.d.ts +3 -0
- package/dist/data/remove-empty.js +11 -0
- package/dist/data/undoable.d.ts +2 -2
- package/dist/data/undoable.js +190 -174
- package/dist/data/with-lifecycle-callbacks.d.ts +45 -17
- package/dist/data/with-lifecycle-callbacks.js +66 -52
- package/dist/environment/application-update-store.js +58 -55
- package/dist/environment/offline-store.js +21 -21
- package/dist/form/array-binding.d.ts +30 -11
- package/dist/form/array-binding.js +184 -166
- package/dist/form/choice-ids.d.ts +7 -0
- package/dist/form/choice-ids.js +11 -0
- package/dist/form/choices-controller.d.ts +3 -2
- package/dist/form/choices-controller.js +302 -275
- package/dist/form/date-format.d.ts +38 -0
- package/dist/form/date-format.js +89 -0
- package/dist/form/dirty-values.d.ts +2 -2
- package/dist/form/dirty-values.js +22 -11
- package/dist/form/duration.d.ts +22 -0
- package/dist/form/duration.js +49 -0
- package/dist/form/edit-create-form.d.ts +12 -5
- package/dist/form/edit-create-form.js +243 -188
- package/dist/form/event-value.d.ts +6 -0
- package/dist/form/event-value.js +17 -0
- package/dist/form/field-error.d.ts +14 -0
- package/dist/form/field-error.js +28 -0
- package/dist/form/field-name.d.ts +20 -0
- package/dist/form/field-name.js +6 -0
- package/dist/form/filter-form-values.js +63 -49
- package/dist/form/form-controller.d.ts +9 -1
- package/dist/form/form-controller.js +165 -160
- package/dist/form/form-groups.d.ts +4 -3
- package/dist/form/form-groups.js +79 -79
- package/dist/form/form-handle.d.ts +175 -0
- package/dist/form/form-handle.js +68 -0
- package/dist/form/input-binding.d.ts +56 -31
- package/dist/form/input-binding.js +169 -118
- package/dist/form/input-values.d.ts +130 -0
- package/dist/form/input-values.js +177 -0
- package/dist/form/json-text.js +51 -37
- package/dist/form/save-pipeline.d.ts +6 -8
- package/dist/form/save-pipeline.js +91 -82
- package/dist/form/set-form-values.d.ts +6 -0
- package/dist/form/set-form-values.js +10 -0
- package/dist/form/source.js +97 -65
- package/dist/form/text-of.d.ts +2 -0
- package/dist/form/text-of.js +7 -0
- package/dist/form/validators.d.ts +58 -19
- package/dist/form/validators.js +97 -71
- package/dist/geo/bbox.d.ts +5 -4
- package/dist/geo/bbox.js +69 -48
- package/dist/geo/bounds.d.ts +14 -3
- package/dist/geo/bounds.js +98 -68
- package/dist/geo/constraints.js +88 -93
- package/dist/geo/coordinates.js +31 -23
- package/dist/geo/editor.d.ts +13 -13
- package/dist/geo/editor.js +176 -153
- package/dist/geo/geocoding.d.ts +4 -4
- package/dist/geo/geocoding.js +38 -41
- package/dist/geo/geojson.d.ts +12 -74
- package/dist/geo/geojson.js +52 -40
- package/dist/geo/geometry-math.d.ts +4 -4
- package/dist/geo/geometry-math.js +100 -93
- package/dist/geo/index.d.ts +7 -6
- package/dist/geo/map-layers.d.ts +42 -7
- package/dist/geo/map-layers.js +88 -62
- package/dist/geo/map-style.js +31 -32
- package/dist/geo/messages.js +48 -45
- package/dist/geo/nominatim.js +88 -80
- package/dist/geo/osm-presets.d.ts +4 -3
- package/dist/geo/osm-presets.js +108 -86
- package/dist/geo/osm-tags.js +14 -12
- package/dist/geo/overpass.d.ts +14 -2
- package/dist/geo/overpass.js +83 -90
- package/dist/geo/shape-value.d.ts +9 -5
- package/dist/geo/shape-value.js +169 -146
- package/dist/geo/snap-to-roads.d.ts +3 -3
- package/dist/geo/snap-to-roads.js +55 -50
- package/dist/geo/throttle.js +36 -39
- package/dist/guards.d.ts +37 -0
- package/dist/guards.js +62 -0
- package/dist/i18n/default-messages.js +34 -29
- package/dist/i18n/english-messages.js +187 -189
- package/dist/i18n/i18n.d.ts +2 -2
- package/dist/i18n/i18n.js +47 -60
- package/dist/i18n/inflection.d.ts +34 -0
- package/dist/i18n/inflection.js +82 -0
- package/dist/i18n/messages.d.ts +10 -2
- package/dist/i18n/messages.js +17 -4
- package/dist/i18n/missing-keys.js +66 -62
- package/dist/i18n/translatable.d.ts +16 -1
- package/dist/i18n/translatable.js +40 -47
- package/dist/index.d.ts +71 -24
- package/dist/index.js +40 -288
- package/dist/json/deep-equal.d.ts +8 -0
- package/dist/json/deep-equal.js +24 -0
- package/dist/json/strip-json-comments.js +38 -42
- package/dist/noop.d.ts +2 -0
- package/dist/noop.js +4 -0
- package/dist/notification/error-message.d.ts +2 -0
- package/dist/notification/error-message.js +10 -0
- package/dist/notification/notification-store.d.ts +3 -2
- package/dist/notification/notification-store.js +41 -45
- package/dist/onboarding-tour/placement.js +63 -78
- package/dist/onboarding-tour/tour-controller.js +46 -54
- package/dist/realtime/add-events-for-mutations.js +75 -81
- package/dist/realtime/announce-lock.js +16 -13
- package/dist/realtime/broadcast-channel-transport.js +65 -59
- package/dist/realtime/copy-members.js +22 -14
- package/dist/realtime/in-memory-lock-provider.js +40 -48
- package/dist/realtime/live.js +95 -101
- package/dist/realtime/lock-options.js +16 -16
- package/dist/realtime/lock-session.js +91 -78
- package/dist/realtime/memory-transport.js +25 -25
- package/dist/realtime/presence.js +120 -122
- package/dist/realtime/realtime-data-provider.d.ts +10 -0
- package/dist/realtime/realtime-data-provider.js +45 -42
- package/dist/realtime/reconnect-backoff.js +17 -0
- package/dist/realtime/sse-transport.d.ts +31 -0
- package/dist/realtime/sse-transport.js +235 -0
- package/dist/realtime/status-store.js +23 -28
- package/dist/realtime/topic-hub.js +62 -71
- package/dist/realtime/topics.js +10 -12
- package/dist/realtime/types.js +10 -12
- package/dist/realtime/unread-count.js +21 -21
- package/dist/realtime/websocket-transport.d.ts +32 -0
- package/dist/realtime/websocket-transport.js +306 -0
- package/dist/resource/describe-resource.d.ts +2 -0
- package/dist/resource/describe-resource.js +232 -219
- package/dist/resource/get-at-path.js +29 -14
- package/dist/resource/identifier.d.ts +18 -0
- package/dist/resource/identifier.js +27 -0
- package/dist/resource/record.d.ts +4 -0
- package/dist/resource/record.js +10 -0
- package/dist/resource/register.d.ts +7 -0
- package/dist/resource/registry-store.d.ts +45 -15
- package/dist/resource/registry-store.js +67 -60
- package/dist/resource/registry.d.ts +10 -0
- package/dist/resource/registry.js +8 -4
- package/dist/resource/source-path.d.ts +16 -1
- package/dist/rich-text/rich-text-extras.d.ts +132 -0
- package/dist/rich-text/rich-text-extras.js +179 -0
- package/dist/rich-text/rich-text-image.d.ts +124 -0
- package/dist/rich-text/rich-text-image.js +163 -0
- package/dist/rich-text/rich-text.d.ts +6 -0
- package/dist/rich-text/rich-text.js +125 -88
- package/dist/router/location.d.ts +22 -4
- package/dist/router/location.js +41 -18
- package/dist/router/match.js +47 -39
- package/dist/router/paths.js +40 -34
- package/dist/router/record-from-location.d.ts +1 -1
- package/dist/router/record-from-location.js +25 -17
- package/dist/store/adapters.js +51 -55
- package/dist/store/micro-store.js +57 -59
- package/dist/store/shallow-equal.d.ts +12 -0
- package/dist/store/shallow-equal.js +20 -0
- package/dist/store/store.js +54 -57
- package/package.json +13 -11
|
@@ -1,246 +1,259 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return formats;
|
|
1
|
+
// src/resource/describe-resource.ts
|
|
2
|
+
var bagOf = (value) => typeof value === "object" && value !== null ? value : void 0;
|
|
3
|
+
var stripZod = (typeName) => typeName.replace(/^Zod/, "").toLowerCase();
|
|
4
|
+
var formatsOf = (checks, format) => {
|
|
5
|
+
const formats = /* @__PURE__ */ new Set();
|
|
6
|
+
if (typeof format === "string") formats.add(format);
|
|
7
|
+
if (Array.isArray(checks)) for (const check of checks) {
|
|
8
|
+
const legacy = bagOf(check)?.kind;
|
|
9
|
+
const modern = bagOf(bagOf(bagOf(check)?._zod)?.def)?.format;
|
|
10
|
+
for (const found of [legacy, modern]) if (typeof found === "string") formats.add(found);
|
|
11
|
+
}
|
|
12
|
+
return formats;
|
|
16
13
|
};
|
|
17
14
|
function readZod3(def) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (typeof def.shape === "function") {
|
|
60
|
-
node.shape = def.shape();
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
return node;
|
|
15
|
+
const typeName = typeof def.typeName === "string" ? def.typeName : "";
|
|
16
|
+
const node = {
|
|
17
|
+
type: stripZod(typeName),
|
|
18
|
+
formats: formatsOf(def.checks, void 0)
|
|
19
|
+
};
|
|
20
|
+
switch (typeName) {
|
|
21
|
+
case "ZodOptional":
|
|
22
|
+
case "ZodNullable":
|
|
23
|
+
case "ZodDefault":
|
|
24
|
+
case "ZodCatch":
|
|
25
|
+
case "ZodReadonly":
|
|
26
|
+
node.inner = def.innerType;
|
|
27
|
+
break;
|
|
28
|
+
case "ZodBranded":
|
|
29
|
+
node.inner = def.type;
|
|
30
|
+
break;
|
|
31
|
+
case "ZodEffects":
|
|
32
|
+
node.inner = def.schema;
|
|
33
|
+
break;
|
|
34
|
+
case "ZodPipeline":
|
|
35
|
+
node.inner = def.in;
|
|
36
|
+
break;
|
|
37
|
+
case "ZodEnum":
|
|
38
|
+
node.entries = Object.fromEntries(def.values.map((value) => [value, value]));
|
|
39
|
+
break;
|
|
40
|
+
case "ZodNativeEnum":
|
|
41
|
+
node.type = "enum";
|
|
42
|
+
node.entries = def.values;
|
|
43
|
+
break;
|
|
44
|
+
case "ZodUnion":
|
|
45
|
+
node.options = def.options;
|
|
46
|
+
break;
|
|
47
|
+
case "ZodLiteral":
|
|
48
|
+
node.value = def.value;
|
|
49
|
+
break;
|
|
50
|
+
case "ZodArray":
|
|
51
|
+
node.element = def.type;
|
|
52
|
+
break;
|
|
53
|
+
case "ZodObject": if (typeof def.shape === "function") node.shape = def.shape();
|
|
54
|
+
}
|
|
55
|
+
return node;
|
|
65
56
|
}
|
|
66
57
|
function readZod4(def) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
break;
|
|
102
|
-
case "object":
|
|
103
|
-
node.shape = def.shape;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
return node;
|
|
58
|
+
const type = typeof def.type === "string" ? def.type : "";
|
|
59
|
+
const node = {
|
|
60
|
+
type,
|
|
61
|
+
formats: formatsOf(def.checks, def.format)
|
|
62
|
+
};
|
|
63
|
+
switch (type) {
|
|
64
|
+
case "optional":
|
|
65
|
+
case "nullable":
|
|
66
|
+
case "nonoptional":
|
|
67
|
+
case "default":
|
|
68
|
+
case "prefault":
|
|
69
|
+
case "catch":
|
|
70
|
+
case "readonly":
|
|
71
|
+
node.inner = def.innerType;
|
|
72
|
+
break;
|
|
73
|
+
case "pipe":
|
|
74
|
+
node.inner = bagOf(bagOf(bagOf(def.in)?._zod)?.def)?.type === "transform" ? def.out : def.in;
|
|
75
|
+
break;
|
|
76
|
+
case "enum":
|
|
77
|
+
node.entries = def.entries;
|
|
78
|
+
break;
|
|
79
|
+
case "union":
|
|
80
|
+
node.options = def.options;
|
|
81
|
+
break;
|
|
82
|
+
case "literal":
|
|
83
|
+
node.value = def.values?.[0];
|
|
84
|
+
if (def.values?.length !== 1) node.type = "literals";
|
|
85
|
+
break;
|
|
86
|
+
case "array":
|
|
87
|
+
node.element = def.element;
|
|
88
|
+
break;
|
|
89
|
+
case "object": node.shape = def.shape;
|
|
90
|
+
}
|
|
91
|
+
return node;
|
|
107
92
|
}
|
|
108
93
|
function read(schema) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
94
|
+
const zod4 = bagOf(bagOf(bagOf(schema)?._zod)?.def);
|
|
95
|
+
if (zod4) return readZod4(zod4);
|
|
96
|
+
const zod3 = bagOf(bagOf(schema)?._def);
|
|
97
|
+
if (zod3) return readZod3(zod3);
|
|
98
|
+
return {
|
|
99
|
+
type: "unknown",
|
|
100
|
+
formats: /* @__PURE__ */ new Set()
|
|
101
|
+
};
|
|
114
102
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
103
|
+
var descriptionOf = (schema) => {
|
|
104
|
+
const description = bagOf(schema)?.description;
|
|
105
|
+
return typeof description === "string" ? description : void 0;
|
|
118
106
|
};
|
|
119
107
|
function unwrap(schema) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
108
|
+
let current = schema;
|
|
109
|
+
let label;
|
|
110
|
+
for (let depth = 0; depth < 64; depth++) {
|
|
111
|
+
const node = read(current);
|
|
112
|
+
label ??= descriptionOf(current);
|
|
113
|
+
if (node.inner === void 0) return {
|
|
114
|
+
node,
|
|
115
|
+
label
|
|
116
|
+
};
|
|
117
|
+
current = node.inner;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
node: read(current),
|
|
121
|
+
label
|
|
122
|
+
};
|
|
129
123
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
var unsupported = (reason) => ({
|
|
125
|
+
kind: "unsupported",
|
|
126
|
+
reason
|
|
133
127
|
});
|
|
134
128
|
function describeString({ formats }) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
129
|
+
if (formats.has("datetime")) return {
|
|
130
|
+
kind: "dateTime",
|
|
131
|
+
field: "DateField",
|
|
132
|
+
input: "DateTimeInput",
|
|
133
|
+
fieldProps: { showTime: true }
|
|
134
|
+
};
|
|
135
|
+
if (formats.has("date")) return {
|
|
136
|
+
kind: "date",
|
|
137
|
+
field: "DateField",
|
|
138
|
+
input: "DateInput"
|
|
139
|
+
};
|
|
140
|
+
if (formats.has("email")) return {
|
|
141
|
+
kind: "email",
|
|
142
|
+
field: "EmailField",
|
|
143
|
+
input: "TextInput"
|
|
144
|
+
};
|
|
145
|
+
if (formats.has("url")) return {
|
|
146
|
+
kind: "url",
|
|
147
|
+
field: "UrlField",
|
|
148
|
+
input: "TextInput"
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
kind: "text",
|
|
152
|
+
field: "TextField",
|
|
153
|
+
input: "TextInput"
|
|
154
|
+
};
|
|
153
155
|
}
|
|
154
156
|
function select(choices) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
return {
|
|
158
|
+
kind: "select",
|
|
159
|
+
field: "SelectField",
|
|
160
|
+
input: "SelectInput",
|
|
161
|
+
choices
|
|
162
|
+
};
|
|
161
163
|
}
|
|
162
|
-
|
|
164
|
+
var toChoices = (ids) => ids.map((id) => ({
|
|
165
|
+
id,
|
|
166
|
+
name: String(id)
|
|
167
|
+
}));
|
|
163
168
|
function describeEnum({ entries = {} }) {
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
const ids = [];
|
|
170
|
+
for (const key of Object.keys(entries)) {
|
|
171
|
+
const value = entries[key];
|
|
172
|
+
if (value === void 0 || typeof entries[value] === "number") continue;
|
|
173
|
+
ids.push(value);
|
|
174
|
+
}
|
|
175
|
+
return select(toChoices(ids));
|
|
166
176
|
}
|
|
167
177
|
function describeUnion({ options = [] }) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
return select(toChoices(ids));
|
|
178
|
+
const ids = [];
|
|
179
|
+
for (const option of options) {
|
|
180
|
+
const { node: member } = unwrap(option);
|
|
181
|
+
const value = member.value;
|
|
182
|
+
if (member.type !== "literal" || typeof value !== "string" && typeof value !== "number") return unsupported("union schema");
|
|
183
|
+
ids.push(value);
|
|
184
|
+
}
|
|
185
|
+
return select(toChoices(ids));
|
|
178
186
|
}
|
|
179
187
|
function describeArray({ element }) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (member?.type === "object") return unsupported("array of objects");
|
|
189
|
-
return unsupported(`array of ${member?.type ?? "unknown"}s`);
|
|
188
|
+
const member = element === void 0 ? void 0 : unwrap(element).node;
|
|
189
|
+
if (member?.type === "string") return {
|
|
190
|
+
kind: "textArray",
|
|
191
|
+
field: "TextArrayField",
|
|
192
|
+
input: "TextArrayInput"
|
|
193
|
+
};
|
|
194
|
+
if (member?.type === "object") return unsupported("array of objects");
|
|
195
|
+
return unsupported(`array of ${member?.type ?? "unknown"}s`);
|
|
190
196
|
}
|
|
191
197
|
function describeKind(node) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
198
|
+
switch (node.type) {
|
|
199
|
+
case "string": return describeString(node);
|
|
200
|
+
case "number": return {
|
|
201
|
+
kind: "number",
|
|
202
|
+
field: "NumberField",
|
|
203
|
+
input: "NumberInput"
|
|
204
|
+
};
|
|
205
|
+
case "boolean": return {
|
|
206
|
+
kind: "boolean",
|
|
207
|
+
field: "BooleanField",
|
|
208
|
+
input: "BooleanInput"
|
|
209
|
+
};
|
|
210
|
+
case "date": return {
|
|
211
|
+
kind: "date",
|
|
212
|
+
field: "DateField",
|
|
213
|
+
input: "DateInput"
|
|
214
|
+
};
|
|
215
|
+
case "enum": return describeEnum(node);
|
|
216
|
+
case "union": return describeUnion(node);
|
|
217
|
+
case "array": return describeArray(node);
|
|
218
|
+
default: return unsupported(`${node.type || "unknown"} schema`);
|
|
219
|
+
}
|
|
210
220
|
}
|
|
221
|
+
/** For core's block editor helpers; not exported from the package index. */
|
|
211
222
|
function describeField(source, schema, references) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
const { node, label } = unwrap(schema);
|
|
224
|
+
const target = references && Object.hasOwn(references, source) ? references[source] : void 0;
|
|
225
|
+
const described = target === void 0 ? describeKind(node) : node.type === "array" ? {
|
|
226
|
+
kind: "referenceArray",
|
|
227
|
+
field: "ReferenceArrayField",
|
|
228
|
+
input: "ReferenceArrayInput",
|
|
229
|
+
reference: target
|
|
230
|
+
} : {
|
|
231
|
+
kind: "reference",
|
|
232
|
+
field: "ReferenceField",
|
|
233
|
+
input: "ReferenceInput",
|
|
234
|
+
reference: target
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
source,
|
|
238
|
+
primary: source === "id",
|
|
239
|
+
...label === void 0 ? {} : { label },
|
|
240
|
+
...described
|
|
241
|
+
};
|
|
231
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Turns a resource's registered Zod schema (Zod 3 or Zod 4) into one descriptor per field, in
|
|
245
|
+
* schema key order. Returns `undefined` when there is no schema to read or it
|
|
246
|
+
* is not an object. Both adapters' guessers build their views from this, never
|
|
247
|
+
* from fetched values.
|
|
248
|
+
*/
|
|
232
249
|
function describeResource(resource, config) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
)
|
|
242
|
-
};
|
|
250
|
+
if (!config?.schema) return void 0;
|
|
251
|
+
const { node } = unwrap(config.schema);
|
|
252
|
+
if (node.type !== "object" || !node.shape) return void 0;
|
|
253
|
+
const { shape } = node;
|
|
254
|
+
return {
|
|
255
|
+
resource,
|
|
256
|
+
fields: Object.keys(shape).map((source) => describeField(source, shape[source], config.references))
|
|
257
|
+
};
|
|
243
258
|
}
|
|
244
|
-
export {
|
|
245
|
-
describeResource
|
|
246
|
-
};
|
|
259
|
+
export { describeField, describeResource };
|
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
// src/resource/get-at-path.ts
|
|
2
|
+
/**
|
|
3
|
+
* The one path grammar chelone reads a record with. Dot members (`a.b`),
|
|
4
|
+
* bracket indices (`a[0].b`) and numeric-dot indices (`a.0.b`) all resolve to
|
|
5
|
+
* the same value, matching `lodash/get`'s relevant semantics.
|
|
6
|
+
*
|
|
7
|
+
* The core tree, calendar and client-list readers read through this, and so do
|
|
8
|
+
* both adapters' `useFieldValue` and `useGetRecordRepresentation`: a `source`
|
|
9
|
+
* written one way reads the same record everywhere, and one walker is left.
|
|
10
|
+
*/
|
|
11
|
+
/** Matches a `[index]` bracket group or a run of non-`.` / non-`[` characters. */
|
|
12
|
+
var PATH_SEGMENT = /\[([^\]]*)\]|[^.[\]]+/g;
|
|
13
|
+
/**
|
|
14
|
+
* Read the value at `source` off `record`. An empty `source` returns the record
|
|
15
|
+
* itself; a step that is null, undefined or a primitive returns `undefined`.
|
|
16
|
+
*
|
|
17
|
+
* An own key equal to the whole `source` wins before any split, as in
|
|
18
|
+
* `lodash/get`: a record that literally holds a `"nested.level"` key — a
|
|
19
|
+
* flattened filter payload, for instance — still reads.
|
|
20
|
+
*/
|
|
2
21
|
function getAtPath(record, source) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return current;
|
|
22
|
+
if (source === "") return record;
|
|
23
|
+
if (record !== null && typeof record === "object" && Object.hasOwn(record, source)) return record[source];
|
|
24
|
+
let current = record;
|
|
25
|
+
for (const match of source.matchAll(PATH_SEGMENT)) {
|
|
26
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
27
|
+
current = current[match[1] !== void 0 ? match[1] : match[0]];
|
|
28
|
+
}
|
|
29
|
+
return current;
|
|
13
30
|
}
|
|
14
|
-
export {
|
|
15
|
-
getAtPath
|
|
16
|
-
};
|
|
31
|
+
export { getAtPath };
|
|
@@ -1 +1,19 @@
|
|
|
1
1
|
export type Identifier = string | number;
|
|
2
|
+
/**
|
|
3
|
+
* True for the value a record id or foreign key holds: a `string` or a `number`.
|
|
4
|
+
* The check for a value read out of a record at a `source`, where the record's
|
|
5
|
+
* own type does not pin the field.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isIdentifier(value: unknown): value is Identifier;
|
|
8
|
+
/**
|
|
9
|
+
* True for an array whose every member is an {@link Identifier}: the shape a
|
|
10
|
+
* to-many foreign key holds on a record.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isIdentifierArray(value: unknown): value is Identifier[];
|
|
13
|
+
/**
|
|
14
|
+
* The ids a to-many foreign key holds. An array that is all ids is returned as
|
|
15
|
+
* it is; one with a member that is not an id keeps its id members, because a
|
|
16
|
+
* nullable `int[]` reads as nulls between real ids and dropping the whole array
|
|
17
|
+
* would hide records the record has. Anything that is not an array is no ids.
|
|
18
|
+
*/
|
|
19
|
+
export declare function identifiersOf(value: unknown): Identifier[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/resource/identifier.ts
|
|
2
|
+
/**
|
|
3
|
+
* True for the value a record id or foreign key holds: a `string` or a `number`.
|
|
4
|
+
* The check for a value read out of a record at a `source`, where the record's
|
|
5
|
+
* own type does not pin the field.
|
|
6
|
+
*/
|
|
7
|
+
function isIdentifier(value) {
|
|
8
|
+
return typeof value === "string" || typeof value === "number";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* True for an array whose every member is an {@link Identifier}: the shape a
|
|
12
|
+
* to-many foreign key holds on a record.
|
|
13
|
+
*/
|
|
14
|
+
function isIdentifierArray(value) {
|
|
15
|
+
return Array.isArray(value) && value.every(isIdentifier);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The ids a to-many foreign key holds. An array that is all ids is returned as
|
|
19
|
+
* it is; one with a member that is not an id keeps its id members, because a
|
|
20
|
+
* nullable `int[]` reads as nulls between real ids and dropping the whole array
|
|
21
|
+
* would hide records the record has. Anything that is not an array is no ids.
|
|
22
|
+
*/
|
|
23
|
+
function identifiersOf(value) {
|
|
24
|
+
if (isIdentifierArray(value)) return value;
|
|
25
|
+
return Array.isArray(value) ? value.filter(isIdentifier) : [];
|
|
26
|
+
}
|
|
27
|
+
export { identifiersOf, isIdentifier, isIdentifierArray };
|
|
@@ -7,3 +7,7 @@ export interface ResourceRecord<TId extends Identifier = Identifier> {
|
|
|
7
7
|
export type LooseRecord = ResourceRecord & {
|
|
8
8
|
[key: string]: unknown;
|
|
9
9
|
};
|
|
10
|
+
/** True for a value shaped like a record: a non-null, non-array object with an `id`. The check for a value that reaches a hook typed `unknown`. */
|
|
11
|
+
export declare function isResourceRecord(value: unknown): value is ResourceRecord;
|
|
12
|
+
/** True for a non-null, non-array object: the shape a record has once it reaches a data provider. */
|
|
13
|
+
export declare function isLooseRecord<T extends ResourceRecord>(value: T): value is T & LooseRecord;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/resource/record.ts
|
|
2
|
+
/** True for a value shaped like a record: a non-null, non-array object with an `id`. The check for a value that reaches a hook typed `unknown`. */
|
|
3
|
+
function isResourceRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && "id" in value;
|
|
5
|
+
}
|
|
6
|
+
/** True for a non-null, non-array object: the shape a record has once it reaches a data provider. */
|
|
7
|
+
function isLooseRecord(value) {
|
|
8
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
export { isLooseRecord, isResourceRecord };
|
|
@@ -20,6 +20,13 @@ export interface Register {
|
|
|
20
20
|
export type RegisteredResources = Register extends {
|
|
21
21
|
resources: infer TResources extends ResourceMap;
|
|
22
22
|
} ? TResources : ResourceMap;
|
|
23
|
+
/**
|
|
24
|
+
* The registered permissions type, or `unknown` when nothing is registered.
|
|
25
|
+
* An app registers it with `interface Register { permissions: string[] }`.
|
|
26
|
+
*/
|
|
27
|
+
export type RegisteredPermissions = Register extends {
|
|
28
|
+
permissions: infer TPermissions;
|
|
29
|
+
} ? TPermissions : unknown;
|
|
23
30
|
/** The registered resource names, or `string` when nothing is registered. */
|
|
24
31
|
export type RegisteredResourceName = keyof RegisteredResources & string;
|
|
25
32
|
/** The record type of a registered resource, or {@link LooseRecord} when it has no schema. */
|