@getaster/data 0.0.0-stage → 0.1.0-preview.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 (84) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +10 -0
  3. package/README.md +6 -2
  4. package/dist/authentication.d.ts +42 -0
  5. package/dist/authentication.js +121 -0
  6. package/dist/changes/changeset.d.ts +47 -0
  7. package/dist/changes/changeset.js +75 -0
  8. package/dist/collection/aggregate.d.ts +22 -0
  9. package/dist/collection/aggregate.js +94 -0
  10. package/dist/collection/collection.d.ts +96 -0
  11. package/dist/collection/collection.js +588 -0
  12. package/dist/collection/grouping.d.ts +75 -0
  13. package/dist/collection/grouping.js +190 -0
  14. package/dist/collection/groups.d.ts +31 -0
  15. package/dist/collection/groups.js +117 -0
  16. package/dist/collection/summary.d.ts +17 -0
  17. package/dist/collection/summary.js +103 -0
  18. package/dist/composition/activity.d.ts +36 -0
  19. package/dist/composition/activity.js +60 -0
  20. package/dist/composition/command.d.ts +22 -0
  21. package/dist/composition/command.js +57 -0
  22. package/dist/composition/lifetime.d.ts +11 -0
  23. package/dist/composition/lifetime.js +33 -0
  24. package/dist/composition/sessions.d.ts +64 -0
  25. package/dist/composition/sessions.js +209 -0
  26. package/dist/context.d.ts +76 -0
  27. package/dist/context.js +211 -0
  28. package/dist/criteria/ast.d.ts +79 -0
  29. package/dist/criteria/ast.js +1 -0
  30. package/dist/criteria/compile.d.ts +37 -0
  31. package/dist/criteria/compile.js +233 -0
  32. package/dist/criteria/evaluate.d.ts +20 -0
  33. package/dist/criteria/evaluate.js +171 -0
  34. package/dist/criteria/filter-draft.d.ts +79 -0
  35. package/dist/criteria/filter-draft.js +320 -0
  36. package/dist/criteria/relative.d.ts +13 -0
  37. package/dist/criteria/relative.js +82 -0
  38. package/dist/criteria/values.d.ts +20 -0
  39. package/dist/criteria/values.js +283 -0
  40. package/dist/edit/edit-model.d.ts +152 -0
  41. package/dist/edit/edit-model.js +620 -0
  42. package/dist/edit/list-edit.d.ts +116 -0
  43. package/dist/edit/list-edit.js +332 -0
  44. package/dist/edit/record-edit.d.ts +93 -0
  45. package/dist/edit/record-edit.js +317 -0
  46. package/dist/export/csv.d.ts +25 -0
  47. package/dist/export/csv.js +75 -0
  48. package/dist/index.d.ts +38 -0
  49. package/dist/index.js +35 -0
  50. package/dist/odata/errors.d.ts +25 -0
  51. package/dist/odata/errors.js +56 -0
  52. package/dist/odata/source.d.ts +65 -0
  53. package/dist/odata/source.js +193 -0
  54. package/dist/progress/status.d.ts +29 -0
  55. package/dist/progress/status.js +105 -0
  56. package/dist/schema/csdl.d.ts +13 -0
  57. package/dist/schema/csdl.js +531 -0
  58. package/dist/schema/model.d.ts +132 -0
  59. package/dist/schema/model.js +1 -0
  60. package/dist/scope/filters.d.ts +130 -0
  61. package/dist/scope/filters.js +349 -0
  62. package/dist/scope/publications.d.ts +27 -0
  63. package/dist/scope/publications.js +74 -0
  64. package/dist/scope/related-aggregate.d.ts +9 -0
  65. package/dist/scope/related-aggregate.js +67 -0
  66. package/dist/scope/scope.d.ts +181 -0
  67. package/dist/scope/scope.js +574 -0
  68. package/dist/selection/selection.d.ts +56 -0
  69. package/dist/selection/selection.js +137 -0
  70. package/dist/store/keys.d.ts +10 -0
  71. package/dist/store/keys.js +21 -0
  72. package/dist/store/store.d.ts +72 -0
  73. package/dist/store/store.js +143 -0
  74. package/dist/template/template.d.ts +19 -0
  75. package/dist/template/template.js +186 -0
  76. package/dist/transport.d.ts +28 -0
  77. package/dist/transport.js +20 -0
  78. package/dist/tree/tree.d.ts +117 -0
  79. package/dist/tree/tree.js +435 -0
  80. package/dist/validate/criteria-rule.d.ts +28 -0
  81. package/dist/validate/criteria-rule.js +22 -0
  82. package/dist/validate/validate.d.ts +13 -0
  83. package/dist/validate/validate.js +123 -0
  84. package/package.json +32 -4
@@ -0,0 +1,181 @@
1
+ import { type ReadonlySignal } from "@preact/signals-core";
2
+ import type { DataContext } from "../context.ts";
3
+ import type { Criteria } from "../criteria/ast.ts";
4
+ import type { EdmType, EntityType, Field, Value } from "../schema/model.ts";
5
+ /**
6
+ * What a component makes visible to its page: named signals, and the entity
7
+ * type behind any that hold a record, so paths into them are typed.
8
+ */
9
+ export interface Publication {
10
+ readonly values: Readonly<Record<string, ReadonlySignal<unknown>>>;
11
+ readonly types?: Readonly<Record<string, EntityType>>;
12
+ /** For a name that holds a record: its fields hidden from the caller (`StoredRecord.hidden`). */
13
+ readonly hidden?: Readonly<Record<string, ReadonlySignal<ReadonlySet<string>>>>;
14
+ }
15
+ /**
16
+ * A condition over the scope. Criteria name paths (`people.selected.name`)
17
+ * where a query names properties; a bare path means "is true", anywhere in
18
+ * the tree.
19
+ */
20
+ export type Condition = Criteria | string | {
21
+ readonly op: "and" | "or";
22
+ readonly args: readonly Condition[];
23
+ } | {
24
+ readonly op: "not";
25
+ readonly arg: Condition;
26
+ };
27
+ /** `condition` as plain criteria, bare paths spelled out. */
28
+ export declare function toCriteria(condition: Condition): Criteria;
29
+ /** A rule with the reason shown when it applies. */
30
+ export interface Ruled {
31
+ readonly when: Condition;
32
+ readonly reason?: string;
33
+ }
34
+ export interface StateRules {
35
+ /** Visible only while this holds. */
36
+ readonly visible?: Condition | Ruled;
37
+ /** Enabled only while this holds. */
38
+ readonly enabled?: Condition | Ruled;
39
+ /** Read-only while this holds. */
40
+ readonly readOnly?: Condition | Ruled;
41
+ /** Required while this holds. */
42
+ readonly required?: Condition | Ruled;
43
+ }
44
+ export type Effect = keyof StateRules;
45
+ export interface FieldState {
46
+ readonly visible: boolean;
47
+ readonly enabled: boolean;
48
+ readonly readOnly: boolean;
49
+ readonly required: boolean;
50
+ /** Why each effect isn't at its default, when a reason was given. */
51
+ readonly reasons: Readonly<Partial<Record<Effect, string>>>;
52
+ }
53
+ export declare const DEFAULT_STATE: FieldState;
54
+ /**
55
+ * One case of a derived value (`scope.select`): when `when` holds (or always,
56
+ * without one), the value is the literal `value`, the value at `path`, or
57
+ * `template` rendered over the scope.
58
+ */
59
+ export type Case = {
60
+ readonly when?: Condition;
61
+ } & ({
62
+ readonly value: Value;
63
+ } | {
64
+ readonly path: string;
65
+ } | {
66
+ readonly template: string;
67
+ } | {
68
+ readonly aggregate: "min" | "max" | "average";
69
+ readonly path: string;
70
+ readonly field: string;
71
+ });
72
+ /** A derived signal owns any related-list requests; dispose it when its consumer goes away. */
73
+ export interface SelectedValue extends ReadonlySignal<unknown> {
74
+ dispose(): void;
75
+ }
76
+ /** Navigations a path may follow from a published record: `task.values.project.lead.name` follows two. */
77
+ export declare const MAX_HOPS = 3;
78
+ /** A published name: its record type and fields' CSDL types, when the publication gives them. */
79
+ export interface ScopeName {
80
+ readonly type?: string;
81
+ readonly fields?: Readonly<Record<string, EdmType>>;
82
+ }
83
+ /** Every published key's names (`scope.schema()`). Plain data. */
84
+ export type ScopeSchema = Readonly<Record<string, Readonly<Record<string, ScopeName>>>>;
85
+ /** One step of `explain`: a rule, what it read and what it decided. */
86
+ export interface Explanation {
87
+ readonly effect: Effect | "derived";
88
+ readonly rule: Condition;
89
+ readonly reason?: string;
90
+ readonly holds: boolean;
91
+ readonly reads: Readonly<Record<string, unknown>>;
92
+ /** Paths it read as unknown: fields hidden on their record. */
93
+ readonly unknown?: readonly string[];
94
+ /** Derived cases, the selected case (zero-based), and its current result. */
95
+ readonly cases?: readonly Case[];
96
+ readonly matched?: number;
97
+ readonly value?: unknown;
98
+ readonly overridden?: boolean;
99
+ readonly current?: unknown;
100
+ readonly error?: string;
101
+ }
102
+ /**
103
+ * A page's published state, by key. Components publish under a key; rules and
104
+ * other components read by path without a reference to the publisher.
105
+ *
106
+ * Invariants: a key has one publisher per scope; reading an unpublished key
107
+ * gives `undefined` and follows it once it's published; a child scope's keys
108
+ * shadow its parent's.
109
+ */
110
+ export declare class PageScope {
111
+ #private;
112
+ readonly parent: PageScope | undefined;
113
+ /** The clock relative dates in rules resolve against; a child scope has its parent's. */
114
+ readonly now: () => number;
115
+ /** Where paths through a navigation find the related record; a child scope has its parent's. */
116
+ readonly ctx: DataContext | undefined;
117
+ constructor(parent?: PageScope, options?: {
118
+ now?: () => number;
119
+ ctx?: DataContext;
120
+ });
121
+ child(): PageScope;
122
+ /** Publishes under `key`; returns the function that withdraws it. */
123
+ publish(key: string, publication: Publication): () => void;
124
+ /** The published keys, nearest scope first. */
125
+ keys(): string[];
126
+ /**
127
+ * What can be read, typed: each published key's names, with the record
128
+ * type and its fields' CSDL types where the publication gives them. For
129
+ * rule builders and tools, to offer and check paths before a rule exists.
130
+ */
131
+ schema(): ScopeSchema;
132
+ /**
133
+ * Why a path can't be read, or `undefined` if it can: an unpublished key,
134
+ * an unknown name, a property the record type lacks, a step past a field,
135
+ * or more than `MAX_HOPS` navigations.
136
+ */
137
+ check(path: string): string | undefined;
138
+ /**
139
+ * A path's value: the key's signal, then properties of the value it holds.
140
+ * From a typed record, a step that names a single-valued navigation reads
141
+ * the related record from the store through `ctx` (fetching it if it isn't
142
+ * loaded), so `task.values.project.name` follows the task's project; it's
143
+ * `undefined` until the record arrives and `null` with no related record.
144
+ */
145
+ value(path: string): ReadonlySignal<unknown>;
146
+ /**
147
+ * A derived value: the first case whose rule holds gives it, and a case
148
+ * without a rule is the default. `undefined` when no case applies, and
149
+ * while a path it has to read is `undefined` (an unpublished key, a
150
+ * related record still loading), so nothing is decided on missing data.
151
+ */
152
+ select(cases: readonly Case[], target?: string): SelectedValue;
153
+ /**
154
+ * The field a path reads, when its publication gives the record type and
155
+ * the path ends on a property of that record or of a record reached
156
+ * through its navigations. Other paths are untyped. A property the record
157
+ * type doesn't have is an error, not a silent null.
158
+ */
159
+ field(path: string): Field | undefined;
160
+ /**
161
+ * Whether `rule` holds, as a signal. A field hidden on its record is
162
+ * unknown to the rule, not null: a test of it is unknown, and a rule holds
163
+ * only when it's true.
164
+ */
165
+ when(rule: Condition): ReadonlySignal<boolean>;
166
+ /** Conservative action availability: every referenced value must be available. */
167
+ available(rule: Condition): ReadonlySignal<boolean>;
168
+ /** Invalid publication/property paths in a rule, without evaluating it. */
169
+ checkRule(rule: Condition): string[];
170
+ /** The state of `target` from its rules; registered for `explain` and `readers`. */
171
+ state(target: string, rules: StateRules, options?: {
172
+ availability?: boolean;
173
+ }): ReadonlySignal<FieldState>;
174
+ /** Every rule registered for `target`, with what it read and decided now. */
175
+ explain(target: string): Explanation[];
176
+ /** The targets whose rules read `path` or anything under it. */
177
+ readers(path: string): {
178
+ target: string;
179
+ effect: Effect;
180
+ }[];
181
+ }