velocious 1.0.474 → 1.0.475

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 (85) hide show
  1. package/README.md +7 -2
  2. package/build/configuration-types.js +38 -1
  3. package/build/configuration.js +41 -1
  4. package/build/database/drivers/base.js +51 -3
  5. package/build/database/drivers/mysql/index.js +74 -7
  6. package/build/database/drivers/sqlite/connection-sql-js.js +16 -5
  7. package/build/database/drivers/sqlite/index.web.js +29 -15
  8. package/build/database/drivers/sqlite/web-persistence.js +521 -0
  9. package/build/environment-handlers/node/cli/commands/generate/frontend-models.js +63 -0
  10. package/build/frontend-model-controller.js +127 -4
  11. package/build/frontend-model-resource/base-resource.js +5 -1
  12. package/build/frontend-models/base.js +146 -2
  13. package/build/frontend-models/query.js +3 -3
  14. package/build/frontend-models/resource-definition.js +304 -2
  15. package/build/routes/hooks/frontend-model-command-route-hook.js +8 -0
  16. package/build/src/configuration-types.d.ts +113 -2
  17. package/build/src/configuration-types.d.ts.map +1 -1
  18. package/build/src/configuration-types.js +35 -2
  19. package/build/src/configuration.d.ts +18 -1
  20. package/build/src/configuration.d.ts.map +1 -1
  21. package/build/src/configuration.js +37 -2
  22. package/build/src/database/drivers/base.d.ts +30 -0
  23. package/build/src/database/drivers/base.d.ts.map +1 -1
  24. package/build/src/database/drivers/base.js +47 -4
  25. package/build/src/database/drivers/mysql/index.d.ts +32 -3
  26. package/build/src/database/drivers/mysql/index.d.ts.map +1 -1
  27. package/build/src/database/drivers/mysql/index.js +65 -7
  28. package/build/src/database/drivers/sqlite/connection-sql-js.d.ts +8 -1
  29. package/build/src/database/drivers/sqlite/connection-sql-js.d.ts.map +1 -1
  30. package/build/src/database/drivers/sqlite/connection-sql-js.js +15 -6
  31. package/build/src/database/drivers/sqlite/index.web.d.ts +5 -5
  32. package/build/src/database/drivers/sqlite/index.web.d.ts.map +1 -1
  33. package/build/src/database/drivers/sqlite/index.web.js +27 -13
  34. package/build/src/database/drivers/sqlite/web-persistence.d.ts +77 -0
  35. package/build/src/database/drivers/sqlite/web-persistence.d.ts.map +1 -0
  36. package/build/src/database/drivers/sqlite/web-persistence.js +464 -0
  37. package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts +30 -0
  38. package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts.map +1 -1
  39. package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.js +53 -1
  40. package/build/src/frontend-model-controller.d.ts +34 -0
  41. package/build/src/frontend-model-controller.d.ts.map +1 -1
  42. package/build/src/frontend-model-controller.js +113 -5
  43. package/build/src/frontend-model-resource/base-resource.d.ts +4 -2
  44. package/build/src/frontend-model-resource/base-resource.d.ts.map +1 -1
  45. package/build/src/frontend-model-resource/base-resource.js +7 -2
  46. package/build/src/frontend-models/base.d.ts +29 -0
  47. package/build/src/frontend-models/base.d.ts.map +1 -1
  48. package/build/src/frontend-models/base.js +131 -3
  49. package/build/src/frontend-models/query.js +4 -4
  50. package/build/src/frontend-models/resource-definition.d.ts +6 -0
  51. package/build/src/frontend-models/resource-definition.d.ts.map +1 -1
  52. package/build/src/frontend-models/resource-definition.js +272 -3
  53. package/build/src/routes/hooks/frontend-model-command-route-hook.d.ts.map +1 -1
  54. package/build/src/routes/hooks/frontend-model-command-route-hook.js +8 -1
  55. package/build/src/sync/device-identity.d.ts +240 -0
  56. package/build/src/sync/device-identity.d.ts.map +1 -0
  57. package/build/src/sync/device-identity.js +454 -0
  58. package/build/src/sync/local-mutation-log.d.ts +212 -0
  59. package/build/src/sync/local-mutation-log.d.ts.map +1 -0
  60. package/build/src/sync/local-mutation-log.js +404 -0
  61. package/build/src/sync/offline-grant.d.ts +157 -0
  62. package/build/src/sync/offline-grant.d.ts.map +1 -0
  63. package/build/src/sync/offline-grant.js +292 -0
  64. package/build/sync/device-identity.js +503 -0
  65. package/build/sync/local-mutation-log.js +448 -0
  66. package/build/sync/offline-grant.js +327 -0
  67. package/build/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +3 -3
  69. package/src/configuration-types.js +38 -1
  70. package/src/configuration.js +41 -1
  71. package/src/database/drivers/base.js +51 -3
  72. package/src/database/drivers/mysql/index.js +74 -7
  73. package/src/database/drivers/sqlite/connection-sql-js.js +16 -5
  74. package/src/database/drivers/sqlite/index.web.js +29 -15
  75. package/src/database/drivers/sqlite/web-persistence.js +521 -0
  76. package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +63 -0
  77. package/src/frontend-model-controller.js +127 -4
  78. package/src/frontend-model-resource/base-resource.js +5 -1
  79. package/src/frontend-models/base.js +146 -2
  80. package/src/frontend-models/query.js +3 -3
  81. package/src/frontend-models/resource-definition.js +304 -2
  82. package/src/routes/hooks/frontend-model-command-route-hook.js +8 -0
  83. package/src/sync/device-identity.js +503 -0
  84. package/src/sync/local-mutation-log.js +448 -0
  85. package/src/sync/offline-grant.js +327 -0
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Local mutation log record query options.
3
+ * @typedef {object} LocalMutationLogRecordsOptions
4
+ * @property {LocalMutationStatus[]} [statuses] - Optional status filter.
5
+ */
6
+ /**
7
+ * Local mutation log row-oriented storage adapter.
8
+ *
9
+ * Implementations should store each mutation log record as its own row/entry.
10
+ * Native apps should back this with SQLite and indexes on storage key, status,
11
+ * and sequence. Avoid storing the whole log as one JSON blob.
12
+ *
13
+ * @typedef {object} LocalMutationLogStorage
14
+ * @property {(storageKey: string, record: LocalMutationLogRecord) => Promise<void> | void} appendRecord - Appends one log record.
15
+ * @property {(storageKey: string, ids: string[]) => Promise<void> | void} deleteRecords - Deletes log records by id.
16
+ * @property {(storageKey: string) => Promise<number> | number} nextSequence - Returns the next local sequence number.
17
+ * @property {(storageKey: string, id: string) => Promise<LocalMutationLogRecord | null | undefined> | LocalMutationLogRecord | null | undefined} record - Reads one log record by id.
18
+ * @property {(storageKey: string, options?: LocalMutationLogRecordsOptions) => Promise<LocalMutationLogRecord[]> | LocalMutationLogRecord[]} records - Reads log records.
19
+ * @property {(storageKey: string, record: LocalMutationLogRecord) => Promise<void> | void} updateRecord - Replaces one log record.
20
+ */
21
+ /**
22
+ * Local sync mutation dependency metadata.
23
+ * @typedef {object} LocalMutationDependency
24
+ * @property {string} clientMutationId - Client mutation id this mutation depends on.
25
+ * @property {string} model - Dependent model/resource name.
26
+ */
27
+ /**
28
+ * Local mutation log status.
29
+ * @typedef {"pending" | "applied-locally" | "peer-applied" | "conflict" | "rejected" | "synced"} LocalMutationStatus
30
+ * */
31
+ /**
32
+ * Local mutation log record.
33
+ * @typedef {object} LocalMutationLogRecord
34
+ * @property {string} createdAt - ISO timestamp when the record was created locally.
35
+ * @property {LocalMutationDependency[]} dependencies - Other local mutations that must replay first.
36
+ * @property {string} id - Local log record id.
37
+ * @property {import("./device-identity.js").SyncMutation} mutation - Device mutation payload.
38
+ * @property {number} sequence - Monotonic local sequence.
39
+ * @property {LocalMutationStatus} status - Local replay/apply status.
40
+ * @property {Record<string, import("../configuration-types.js").FrontendModelSyncJsonValue>} [syncResult] - Backend replay/result metadata.
41
+ * @property {string} updatedAt - ISO timestamp when the record was last changed.
42
+ */
43
+ /** Client-side append-only sync mutation log with pluggable persistent storage. */
44
+ export default class LocalMutationLog {
45
+ /**
46
+ * Creates a local mutation log.
47
+ * @param {object} args - Arguments.
48
+ * @param {() => string} [args.idGenerator] - Record id generator.
49
+ * @param {() => Date} [args.now] - Clock callback.
50
+ * @param {LocalMutationLogStorage} args.storage - Persistent storage adapter.
51
+ * @param {string} [args.storageKey] - Storage key.
52
+ */
53
+ constructor({ idGenerator, now, storage, storageKey }: {
54
+ idGenerator?: (() => string) | undefined;
55
+ now?: (() => Date) | undefined;
56
+ storage: LocalMutationLogStorage;
57
+ storageKey?: string | undefined;
58
+ });
59
+ idGenerator: () => string;
60
+ now: () => Date;
61
+ storage: LocalMutationLogStorage;
62
+ storageKey: string;
63
+ /**
64
+ * Appends a pending mutation record.
65
+ * @param {object} args - Arguments.
66
+ * @param {LocalMutationDependency[]} [args.dependencies] - Mutation dependencies.
67
+ * @param {import("./device-identity.js").SyncMutation} args.mutation - Mutation payload.
68
+ * @returns {Promise<LocalMutationLogRecord>} - Created log record.
69
+ */
70
+ append({ dependencies, mutation }: {
71
+ dependencies?: LocalMutationDependency[] | undefined;
72
+ mutation: import("./device-identity.js").SyncMutation;
73
+ }): Promise<LocalMutationLogRecord>;
74
+ /**
75
+ * Returns all records ordered by local sequence.
76
+ * @returns {Promise<LocalMutationLogRecord[]>} - Log records.
77
+ */
78
+ records(): Promise<LocalMutationLogRecord[]>;
79
+ /**
80
+ * Returns records that still need local/server reconciliation.
81
+ * @returns {Promise<LocalMutationLogRecord[]>} - Pending records.
82
+ */
83
+ pendingRecords(): Promise<LocalMutationLogRecord[]>;
84
+ /**
85
+ * Updates a record status.
86
+ * @param {object} args - Arguments.
87
+ * @param {string} args.id - Record id.
88
+ * @param {LocalMutationStatus} args.status - New status.
89
+ * @param {Record<string, import("../configuration-types.js").FrontendModelSyncJsonValue>} [args.syncResult] - Result metadata.
90
+ * @returns {Promise<LocalMutationLogRecord>} - Updated record.
91
+ */
92
+ updateStatus({ id, status, syncResult }: {
93
+ id: string;
94
+ status: LocalMutationStatus;
95
+ syncResult?: Record<string, import("../configuration-types.js").FrontendModelSyncJsonValue> | undefined;
96
+ }): Promise<LocalMutationLogRecord>;
97
+ /**
98
+ * Prunes terminal records that are no longer needed for replay dependencies.
99
+ * @param {object} [args] - Compaction options.
100
+ * @param {number} [args.maxTerminalRecords] - Maximum terminal records to retain.
101
+ * @param {number} [args.terminalRetentionMs] - Minimum age before pruning terminal records.
102
+ * @returns {Promise<{deletedRecordIds: string[]}>} - Compaction result.
103
+ */
104
+ compact({ maxTerminalRecords, terminalRetentionMs }?: {
105
+ maxTerminalRecords?: number | undefined;
106
+ terminalRetentionMs?: number | undefined;
107
+ }): Promise<{
108
+ deletedRecordIds: string[];
109
+ }>;
110
+ /**
111
+ * Returns the current log timestamp.
112
+ * @returns {string} - Current ISO timestamp.
113
+ */
114
+ currentTimestamp(): string;
115
+ }
116
+ /**
117
+ * Local mutation log record query options.
118
+ */
119
+ export type LocalMutationLogRecordsOptions = {
120
+ /**
121
+ * - Optional status filter.
122
+ */
123
+ statuses?: LocalMutationStatus[] | undefined;
124
+ };
125
+ /**
126
+ * Local mutation log row-oriented storage adapter.
127
+ *
128
+ * Implementations should store each mutation log record as its own row/entry.
129
+ * Native apps should back this with SQLite and indexes on storage key, status,
130
+ * and sequence. Avoid storing the whole log as one JSON blob.
131
+ */
132
+ export type LocalMutationLogStorage = {
133
+ /**
134
+ * - Appends one log record.
135
+ */
136
+ appendRecord: (storageKey: string, record: LocalMutationLogRecord) => Promise<void> | void;
137
+ /**
138
+ * - Deletes log records by id.
139
+ */
140
+ deleteRecords: (storageKey: string, ids: string[]) => Promise<void> | void;
141
+ /**
142
+ * - Returns the next local sequence number.
143
+ */
144
+ nextSequence: (storageKey: string) => Promise<number> | number;
145
+ /**
146
+ * - Reads one log record by id.
147
+ */
148
+ record: (storageKey: string, id: string) => Promise<LocalMutationLogRecord | null | undefined> | LocalMutationLogRecord | null | undefined;
149
+ /**
150
+ * - Reads log records.
151
+ */
152
+ records: (storageKey: string, options?: LocalMutationLogRecordsOptions) => Promise<LocalMutationLogRecord[]> | LocalMutationLogRecord[];
153
+ /**
154
+ * - Replaces one log record.
155
+ */
156
+ updateRecord: (storageKey: string, record: LocalMutationLogRecord) => Promise<void> | void;
157
+ };
158
+ /**
159
+ * Local sync mutation dependency metadata.
160
+ */
161
+ export type LocalMutationDependency = {
162
+ /**
163
+ * - Client mutation id this mutation depends on.
164
+ */
165
+ clientMutationId: string;
166
+ /**
167
+ * - Dependent model/resource name.
168
+ */
169
+ model: string;
170
+ };
171
+ /**
172
+ * Local mutation log status.
173
+ */
174
+ export type LocalMutationStatus = "pending" | "applied-locally" | "peer-applied" | "conflict" | "rejected" | "synced";
175
+ /**
176
+ * Local mutation log record.
177
+ */
178
+ export type LocalMutationLogRecord = {
179
+ /**
180
+ * - ISO timestamp when the record was created locally.
181
+ */
182
+ createdAt: string;
183
+ /**
184
+ * - Other local mutations that must replay first.
185
+ */
186
+ dependencies: LocalMutationDependency[];
187
+ /**
188
+ * - Local log record id.
189
+ */
190
+ id: string;
191
+ /**
192
+ * - Device mutation payload.
193
+ */
194
+ mutation: import("./device-identity.js").SyncMutation;
195
+ /**
196
+ * - Monotonic local sequence.
197
+ */
198
+ sequence: number;
199
+ /**
200
+ * - Local replay/apply status.
201
+ */
202
+ status: LocalMutationStatus;
203
+ /**
204
+ * - Backend replay/result metadata.
205
+ */
206
+ syncResult?: Record<string, import("../configuration-types.js").FrontendModelSyncJsonValue> | undefined;
207
+ /**
208
+ * - ISO timestamp when the record was last changed.
209
+ */
210
+ updatedAt: string;
211
+ };
212
+ //# sourceMappingURL=local-mutation-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-mutation-log.d.ts","sourceRoot":"","sources":["../../../src/sync/local-mutation-log.js"],"names":[],"mappings":"AAUA;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH;;;KAGK;AAEL;;;;;;;;;;;GAWG;AAEH,mFAAmF;AACnF;IACE;;;;;;;OAOG;IACH,uDALG;QAA4B,WAAW,UAAzB,MAAM;QACM,GAAG,UAAf,IAAI;QACoB,OAAO,EAArC,uBAAuB;QACT,UAAU;KAClC,EAUA;IAJC,mBAVe,MAAM,CAUS;IAC9B,WAVe,IAAI,CAUL;IACd,iCAAsB;IACtB,mBAA4B;IAG9B;;;;;;OAMG;IACH,mCAJG;QAAyC,YAAY;QACK,QAAQ,EAA1D,OAAO,sBAAsB,EAAE,YAAY;KACnD,GAAU,OAAO,CAAC,sBAAsB,CAAC,CAmB3C;IAED;;;OAGG;IACH,WAFa,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAI7C;IAED;;;OAGG;IACH,kBAFa,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAI7C;IAED;;;;;;;OAOG;IACH,yCALG;QAAqB,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