@b2bc-devkit/sheetorm 1.1.0 → 1.2.3
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/package.json +171 -86
- package/readme.md +57 -17
- package/dist/npm/SheetOrm.d.ts +0 -41
- package/dist/npm/SheetOrm.d.ts.map +0 -1
- package/dist/npm/SheetOrm.js +0 -41
- package/dist/npm/SheetOrm.js.map +0 -1
- package/dist/npm/core/Decorators.d.ts +0 -145
- package/dist/npm/core/Decorators.d.ts.map +0 -1
- package/dist/npm/core/Decorators.js +0 -226
- package/dist/npm/core/Decorators.js.map +0 -1
- package/dist/npm/core/Record.d.ts +0 -178
- package/dist/npm/core/Record.d.ts.map +0 -1
- package/dist/npm/core/Record.js +0 -313
- package/dist/npm/core/Record.js.map +0 -1
- package/dist/npm/core/RecordConstructor.d.ts +0 -20
- package/dist/npm/core/RecordConstructor.d.ts.map +0 -1
- package/dist/npm/core/RecordConstructor.js +0 -2
- package/dist/npm/core/RecordConstructor.js.map +0 -1
- package/dist/npm/core/RecordStatic.d.ts +0 -23
- package/dist/npm/core/RecordStatic.d.ts.map +0 -1
- package/dist/npm/core/RecordStatic.js +0 -2
- package/dist/npm/core/RecordStatic.js.map +0 -1
- package/dist/npm/core/Registry.d.ts +0 -101
- package/dist/npm/core/Registry.d.ts.map +0 -1
- package/dist/npm/core/Registry.js +0 -226
- package/dist/npm/core/Registry.js.map +0 -1
- package/dist/npm/core/SheetRepository.d.ts +0 -331
- package/dist/npm/core/SheetRepository.d.ts.map +0 -1
- package/dist/npm/core/SheetRepository.js +0 -1041
- package/dist/npm/core/SheetRepository.js.map +0 -1
- package/dist/npm/core/cache/MemoryCache.d.ts +0 -67
- package/dist/npm/core/cache/MemoryCache.d.ts.map +0 -1
- package/dist/npm/core/cache/MemoryCache.js +0 -112
- package/dist/npm/core/cache/MemoryCache.js.map +0 -1
- package/dist/npm/core/types/Entity.d.ts +0 -21
- package/dist/npm/core/types/Entity.d.ts.map +0 -1
- package/dist/npm/core/types/Entity.js +0 -2
- package/dist/npm/core/types/Entity.js.map +0 -1
- package/dist/npm/core/types/FieldDefinition.d.ts +0 -21
- package/dist/npm/core/types/FieldDefinition.d.ts.map +0 -1
- package/dist/npm/core/types/FieldDefinition.js +0 -2
- package/dist/npm/core/types/FieldDefinition.js.map +0 -1
- package/dist/npm/core/types/FieldType.d.ts +0 -12
- package/dist/npm/core/types/FieldType.d.ts.map +0 -1
- package/dist/npm/core/types/FieldType.js +0 -2
- package/dist/npm/core/types/FieldType.js.map +0 -1
- package/dist/npm/core/types/Filter.d.ts +0 -16
- package/dist/npm/core/types/Filter.d.ts.map +0 -1
- package/dist/npm/core/types/Filter.js +0 -2
- package/dist/npm/core/types/Filter.js.map +0 -1
- package/dist/npm/core/types/FilterOperator.d.ts +0 -16
- package/dist/npm/core/types/FilterOperator.d.ts.map +0 -1
- package/dist/npm/core/types/FilterOperator.js +0 -2
- package/dist/npm/core/types/FilterOperator.js.map +0 -1
- package/dist/npm/core/types/GroupResult.d.ts +0 -14
- package/dist/npm/core/types/GroupResult.d.ts.map +0 -1
- package/dist/npm/core/types/GroupResult.js +0 -2
- package/dist/npm/core/types/GroupResult.js.map +0 -1
- package/dist/npm/core/types/ICacheProvider.d.ts +0 -20
- package/dist/npm/core/types/ICacheProvider.d.ts.map +0 -1
- package/dist/npm/core/types/ICacheProvider.js +0 -2
- package/dist/npm/core/types/ICacheProvider.js.map +0 -1
- package/dist/npm/core/types/ISheetAdapter.d.ts +0 -53
- package/dist/npm/core/types/ISheetAdapter.d.ts.map +0 -1
- package/dist/npm/core/types/ISheetAdapter.js +0 -2
- package/dist/npm/core/types/ISheetAdapter.js.map +0 -1
- package/dist/npm/core/types/ISpreadsheetAdapter.d.ts +0 -41
- package/dist/npm/core/types/ISpreadsheetAdapter.d.ts.map +0 -1
- package/dist/npm/core/types/ISpreadsheetAdapter.js +0 -2
- package/dist/npm/core/types/ISpreadsheetAdapter.js.map +0 -1
- package/dist/npm/core/types/IndexDefinition.d.ts +0 -16
- package/dist/npm/core/types/IndexDefinition.d.ts.map +0 -1
- package/dist/npm/core/types/IndexDefinition.js +0 -2
- package/dist/npm/core/types/IndexDefinition.js.map +0 -1
- package/dist/npm/core/types/LifecycleHooks.d.ts +0 -32
- package/dist/npm/core/types/LifecycleHooks.d.ts.map +0 -1
- package/dist/npm/core/types/LifecycleHooks.js +0 -2
- package/dist/npm/core/types/LifecycleHooks.js.map +0 -1
- package/dist/npm/core/types/PaginatedResult.d.ts +0 -18
- package/dist/npm/core/types/PaginatedResult.d.ts.map +0 -1
- package/dist/npm/core/types/PaginatedResult.js +0 -2
- package/dist/npm/core/types/PaginatedResult.js.map +0 -1
- package/dist/npm/core/types/QueryOptions.d.ts +0 -21
- package/dist/npm/core/types/QueryOptions.d.ts.map +0 -1
- package/dist/npm/core/types/QueryOptions.js +0 -2
- package/dist/npm/core/types/QueryOptions.js.map +0 -1
- package/dist/npm/core/types/SortClause.d.ts +0 -10
- package/dist/npm/core/types/SortClause.d.ts.map +0 -1
- package/dist/npm/core/types/SortClause.js +0 -2
- package/dist/npm/core/types/SortClause.js.map +0 -1
- package/dist/npm/core/types/SystemColumns.d.ts +0 -16
- package/dist/npm/core/types/SystemColumns.d.ts.map +0 -1
- package/dist/npm/core/types/SystemColumns.js +0 -16
- package/dist/npm/core/types/SystemColumns.js.map +0 -1
- package/dist/npm/core/types/TableSchema.d.ts +0 -24
- package/dist/npm/core/types/TableSchema.d.ts.map +0 -1
- package/dist/npm/core/types/TableSchema.js +0 -2
- package/dist/npm/core/types/TableSchema.js.map +0 -1
- package/dist/npm/index/IndexMeta.d.ts +0 -16
- package/dist/npm/index/IndexMeta.d.ts.map +0 -1
- package/dist/npm/index/IndexMeta.js +0 -2
- package/dist/npm/index/IndexMeta.js.map +0 -1
- package/dist/npm/index/IndexStore.d.ts +0 -397
- package/dist/npm/index/IndexStore.d.ts.map +0 -1
- package/dist/npm/index/IndexStore.js +0 -1102
- package/dist/npm/index/IndexStore.js.map +0 -1
- package/dist/npm/index.d.ts +0 -115
- package/dist/npm/index.d.ts.map +0 -1
- package/dist/npm/index.js +0 -367
- package/dist/npm/index.js.map +0 -1
- package/dist/npm/query/Query.d.ts +0 -176
- package/dist/npm/query/Query.d.ts.map +0 -1
- package/dist/npm/query/Query.js +0 -270
- package/dist/npm/query/Query.js.map +0 -1
- package/dist/npm/query/QueryEngine.d.ts +0 -140
- package/dist/npm/query/QueryEngine.d.ts.map +0 -1
- package/dist/npm/query/QueryEngine.js +0 -453
- package/dist/npm/query/QueryEngine.js.map +0 -1
- package/dist/npm/storage/GoogleSheetAdapter.d.ts +0 -119
- package/dist/npm/storage/GoogleSheetAdapter.d.ts.map +0 -1
- package/dist/npm/storage/GoogleSheetAdapter.js +0 -238
- package/dist/npm/storage/GoogleSheetAdapter.js.map +0 -1
- package/dist/npm/storage/GoogleSpreadsheetAdapter.d.ts +0 -65
- package/dist/npm/storage/GoogleSpreadsheetAdapter.d.ts.map +0 -1
- package/dist/npm/storage/GoogleSpreadsheetAdapter.js +0 -119
- package/dist/npm/storage/GoogleSpreadsheetAdapter.js.map +0 -1
- package/dist/npm/testing/ParityCatalog.d.ts +0 -38
- package/dist/npm/testing/ParityCatalog.d.ts.map +0 -1
- package/dist/npm/testing/ParityCatalog.js +0 -404
- package/dist/npm/testing/ParityCatalog.js.map +0 -1
- package/dist/npm/testing/RuntimeBenchmark.d.ts +0 -37
- package/dist/npm/testing/RuntimeBenchmark.d.ts.map +0 -1
- package/dist/npm/testing/RuntimeBenchmark.js +0 -449
- package/dist/npm/testing/RuntimeBenchmark.js.map +0 -1
- package/dist/npm/testing/RuntimeParity.d.ts +0 -62
- package/dist/npm/testing/RuntimeParity.d.ts.map +0 -1
- package/dist/npm/testing/RuntimeParity.js +0 -4126
- package/dist/npm/testing/RuntimeParity.js.map +0 -1
- package/dist/npm/utils/Serialization.d.ts +0 -111
- package/dist/npm/utils/Serialization.d.ts.map +0 -1
- package/dist/npm/utils/Serialization.js +0 -281
- package/dist/npm/utils/Serialization.js.map +0 -1
- package/dist/npm/utils/SheetOrmLogger.d.ts +0 -31
- package/dist/npm/utils/SheetOrmLogger.d.ts.map +0 -1
- package/dist/npm/utils/SheetOrmLogger.js +0 -42
- package/dist/npm/utils/SheetOrmLogger.js.map +0 -1
- package/dist/npm/utils/Uuid.d.ts +0 -29
- package/dist/npm/utils/Uuid.d.ts.map +0 -1
- package/dist/npm/utils/Uuid.js +0 -86
- package/dist/npm/utils/Uuid.js.map +0 -1
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serialization utilities for converting between entity objects and Google Sheet rows.
|
|
3
|
-
*
|
|
4
|
-
* This module handles the bidirectional mapping:
|
|
5
|
-
* Entity object ←→ sheet row (unknown[])
|
|
6
|
-
*
|
|
7
|
-
* Each conversion is type-aware: when a FieldDefinition carries an explicit `type`,
|
|
8
|
-
* the value is coerced accordingly. When type is omitted, the serializer infers
|
|
9
|
-
* the best representation from the JavaScript runtime type.
|
|
10
|
-
*
|
|
11
|
-
* @module Serialization
|
|
12
|
-
*/
|
|
13
|
-
import { SystemColumns } from "../core/types/SystemColumns.js";
|
|
14
|
-
/**
|
|
15
|
-
* Serialize a single field value for storage in a Google Sheet cell.
|
|
16
|
-
*
|
|
17
|
-
* Conversion rules by FieldType:
|
|
18
|
-
* - "string" / "reference" → String()
|
|
19
|
-
* - "number" → Number(); non-finite values become empty string
|
|
20
|
-
* - "boolean" → true/false; strings "true"/"1"/"yes" are truthy
|
|
21
|
-
* - "date" → ISO 8601 string; invalid Date → empty string
|
|
22
|
-
* - "json" → JSON.stringify()
|
|
23
|
-
*
|
|
24
|
-
* When fieldDef.type is undefined, the JS runtime type is inspected
|
|
25
|
-
* (number, boolean, Date, object → JSON, else String).
|
|
26
|
-
*
|
|
27
|
-
* @param value - The entity field value to serialize.
|
|
28
|
-
* @param fieldDef - Field metadata (type, name, etc.).
|
|
29
|
-
* @returns A cell-safe value (string, number, or boolean).
|
|
30
|
-
*/
|
|
31
|
-
function serializeValue(value, fieldDef) {
|
|
32
|
-
// Null / undefined → empty cell
|
|
33
|
-
if (value === null || value === undefined)
|
|
34
|
-
return "";
|
|
35
|
-
// --- Explicit type branch ---
|
|
36
|
-
if (fieldDef.type) {
|
|
37
|
-
switch (fieldDef.type) {
|
|
38
|
-
case "string":
|
|
39
|
-
case "reference":
|
|
40
|
-
return String(value);
|
|
41
|
-
case "number": {
|
|
42
|
-
// Accept numeric values directly; coerce strings to numbers
|
|
43
|
-
if (typeof value === "number")
|
|
44
|
-
return Number.isFinite(value) ? value : "";
|
|
45
|
-
const num = Number(value);
|
|
46
|
-
return Number.isFinite(num) ? num : "";
|
|
47
|
-
}
|
|
48
|
-
case "boolean": {
|
|
49
|
-
// Accept booleans directly; coerce numbers and strings
|
|
50
|
-
if (typeof value === "boolean")
|
|
51
|
-
return value;
|
|
52
|
-
if (typeof value === "number")
|
|
53
|
-
return !isNaN(value) && value !== 0;
|
|
54
|
-
const lower = typeof value === "string" ? value.toLowerCase().trim() : "";
|
|
55
|
-
return lower === "true" || lower === "1" || lower === "yes";
|
|
56
|
-
}
|
|
57
|
-
case "date":
|
|
58
|
-
// Dates are stored as ISO 8601 strings; invalid dates become empty
|
|
59
|
-
if (value instanceof Date)
|
|
60
|
-
return isNaN(value.getTime()) ? "" : value.toISOString();
|
|
61
|
-
return String(value);
|
|
62
|
-
case "json":
|
|
63
|
-
// Arbitrary structures are JSON-stringified for cell storage
|
|
64
|
-
return JSON.stringify(value);
|
|
65
|
-
default:
|
|
66
|
-
return String(value);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// --- Auto-infer branch (no explicit type) ---
|
|
70
|
-
if (typeof value === "number")
|
|
71
|
-
return value;
|
|
72
|
-
if (typeof value === "boolean")
|
|
73
|
-
return value;
|
|
74
|
-
if (value instanceof Date)
|
|
75
|
-
return isNaN(value.getTime()) ? "" : value.toISOString();
|
|
76
|
-
if (typeof value === "object")
|
|
77
|
-
return JSON.stringify(value);
|
|
78
|
-
return String(value);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Deserialize a cell value read from a Google Sheet into a typed JavaScript value.
|
|
82
|
-
*
|
|
83
|
-
* Empty / null cells return the field's defaultValue (or null if none is defined).
|
|
84
|
-
* Conversion mirrors serializeValue in reverse:
|
|
85
|
-
* - "number" → Number(); non-finite → null
|
|
86
|
-
* - "boolean" → true/false from various truthy representations
|
|
87
|
-
* - "date" → ISO string (Date objects are converted)
|
|
88
|
-
* - "json" → JSON.parse(); malformed JSON → null
|
|
89
|
-
* - "string" / "reference" → String()
|
|
90
|
-
*
|
|
91
|
-
* When fieldDef.type is undefined, the raw cell value is returned as-is,
|
|
92
|
-
* trusting the Google Sheets storage layer to preserve JavaScript types.
|
|
93
|
-
*
|
|
94
|
-
* @param cellValue - Raw value read from the sheet cell.
|
|
95
|
-
* @param fieldDef - Field metadata describing the expected type.
|
|
96
|
-
* @returns The deserialized JavaScript value.
|
|
97
|
-
*/
|
|
98
|
-
function deserializeValue(cellValue, fieldDef) {
|
|
99
|
-
// Empty cell → use default or null
|
|
100
|
-
if (cellValue === "" || cellValue === null || cellValue === undefined) {
|
|
101
|
-
return fieldDef.defaultValue ?? null;
|
|
102
|
-
}
|
|
103
|
-
// --- Explicit type branch ---
|
|
104
|
-
if (fieldDef.type) {
|
|
105
|
-
switch (fieldDef.type) {
|
|
106
|
-
case "string":
|
|
107
|
-
case "reference":
|
|
108
|
-
return String(cellValue);
|
|
109
|
-
case "number": {
|
|
110
|
-
const num = Number(cellValue);
|
|
111
|
-
return Number.isFinite(num) ? num : null;
|
|
112
|
-
}
|
|
113
|
-
case "boolean":
|
|
114
|
-
// Accept native booleans, numbers, and truthy strings
|
|
115
|
-
if (typeof cellValue === "boolean")
|
|
116
|
-
return cellValue;
|
|
117
|
-
if (typeof cellValue === "number")
|
|
118
|
-
return !isNaN(cellValue) && cellValue !== 0;
|
|
119
|
-
if (typeof cellValue === "string") {
|
|
120
|
-
const lower = cellValue.toLowerCase().trim();
|
|
121
|
-
return lower === "true" || lower === "1" || lower === "yes";
|
|
122
|
-
}
|
|
123
|
-
return Boolean(cellValue);
|
|
124
|
-
case "date":
|
|
125
|
-
// Normalise GAS Date objects to ISO strings
|
|
126
|
-
if (cellValue instanceof Date)
|
|
127
|
-
return isNaN(cellValue.getTime()) ? null : cellValue.toISOString();
|
|
128
|
-
return String(cellValue);
|
|
129
|
-
case "json":
|
|
130
|
-
// Parse JSON-stringified cell; return null on malformed input
|
|
131
|
-
if (typeof cellValue === "string" && cellValue.length > 0) {
|
|
132
|
-
try {
|
|
133
|
-
return JSON.parse(cellValue);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return cellValue;
|
|
140
|
-
default:
|
|
141
|
-
return cellValue;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// Auto: trust storage layer to return the correct JS type
|
|
145
|
-
return cellValue;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Build the complete header row for a SheetORM table.
|
|
149
|
-
*
|
|
150
|
-
* Layout: `[__id, __createdAt, __updatedAt, ...userFields]`.
|
|
151
|
-
* This order is assumed by entityToRow / rowToEntity and must remain stable.
|
|
152
|
-
*
|
|
153
|
-
* @param fields - User-defined field definitions (from decorators).
|
|
154
|
-
* @returns An array of column header strings.
|
|
155
|
-
*/
|
|
156
|
-
function buildHeaders(fields) {
|
|
157
|
-
// System columns always occupy the first three positions
|
|
158
|
-
return [SystemColumns.ID, SystemColumns.CREATED_AT, SystemColumns.UPDATED_AT, ...fields.map((f) => f.name)];
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Convert an entity object into a row array matching the header order.
|
|
162
|
-
*
|
|
163
|
-
* The resulting array can be passed directly to ISheetAdapter.appendRow()
|
|
164
|
-
* or updateRow(). System columns are placed first, followed by user
|
|
165
|
-
* fields in the same order as the header row.
|
|
166
|
-
*
|
|
167
|
-
* @param entity - The entity to serialise.
|
|
168
|
-
* @param fields - User-defined field definitions.
|
|
169
|
-
* @param headers - Full header row (system + user columns).
|
|
170
|
-
* @param fieldMap - Optional pre-built name→FieldDefinition map for O(1) lookup.
|
|
171
|
-
* When omitted, falls back to linear scan (fine for <20 fields).
|
|
172
|
-
* @returns An unknown[] row array ready to be written to the sheet.
|
|
173
|
-
*/
|
|
174
|
-
function entityToRow(entity, fields, headers, fieldMap) {
|
|
175
|
-
const len = headers.length;
|
|
176
|
-
const row = new Array(len);
|
|
177
|
-
// Use provided fieldMap or fall back to linear scan for small field lists
|
|
178
|
-
const useMap = fieldMap !== undefined;
|
|
179
|
-
for (let i = 0; i < len; i++) {
|
|
180
|
-
const col = headers[i];
|
|
181
|
-
// System columns are handled directly (no serialization needed)
|
|
182
|
-
if (col === SystemColumns.ID) {
|
|
183
|
-
row[i] = entity.__id;
|
|
184
|
-
}
|
|
185
|
-
else if (col === SystemColumns.CREATED_AT) {
|
|
186
|
-
row[i] = entity.__createdAt ?? "";
|
|
187
|
-
}
|
|
188
|
-
else if (col === SystemColumns.UPDATED_AT) {
|
|
189
|
-
row[i] = entity.__updatedAt ?? "";
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
// User field: look up the definition and serialize the value
|
|
193
|
-
const fieldDef = useMap ? fieldMap.get(col) : fields.find((f) => f.name === col);
|
|
194
|
-
if (fieldDef) {
|
|
195
|
-
row[i] = serializeValue(entity[col], fieldDef);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
// Unknown column — pass through raw value (defensive, shouldn't happen normally)
|
|
199
|
-
row[i] = entity[col] ?? "";
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return row;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Convert a sheet row array back into a typed entity object.
|
|
207
|
-
*
|
|
208
|
-
* Iterates over the header columns and deserializes each cell value
|
|
209
|
-
* into the appropriate JS type.
|
|
210
|
-
*
|
|
211
|
-
* @param row - Raw row data from ISheetAdapter.getAllData().
|
|
212
|
-
* @param headers - Full header row (system + user columns).
|
|
213
|
-
* @param fields - User-defined field definitions.
|
|
214
|
-
* @param fieldMap - Optional pre-built name→FieldDefinition map for O(1) lookup.
|
|
215
|
-
* @returns A fully hydrated entity object of type T.
|
|
216
|
-
*/
|
|
217
|
-
function rowToEntity(row, headers, fields, fieldMap) {
|
|
218
|
-
const entity = {};
|
|
219
|
-
// Use provided fieldMap or fall back to linear scan for small field lists
|
|
220
|
-
const useMap = fieldMap !== undefined;
|
|
221
|
-
const rowLen = row.length;
|
|
222
|
-
for (let i = 0, len = headers.length; i < len; i++) {
|
|
223
|
-
const col = headers[i];
|
|
224
|
-
// Guard against short rows (missing trailing columns)
|
|
225
|
-
const cellValue = i < rowLen ? row[i] : "";
|
|
226
|
-
if (col === SystemColumns.ID) {
|
|
227
|
-
// __id is always stored as a string
|
|
228
|
-
entity.__id = String(cellValue);
|
|
229
|
-
}
|
|
230
|
-
else if (col === SystemColumns.CREATED_AT) {
|
|
231
|
-
// GAS may return a Date object; normalise to ISO string
|
|
232
|
-
entity.__createdAt =
|
|
233
|
-
cellValue instanceof Date
|
|
234
|
-
? cellValue.toISOString()
|
|
235
|
-
: cellValue !== "" && cellValue !== null && cellValue !== undefined
|
|
236
|
-
? String(cellValue)
|
|
237
|
-
: undefined;
|
|
238
|
-
}
|
|
239
|
-
else if (col === SystemColumns.UPDATED_AT) {
|
|
240
|
-
entity.__updatedAt =
|
|
241
|
-
cellValue instanceof Date
|
|
242
|
-
? cellValue.toISOString()
|
|
243
|
-
: cellValue !== "" && cellValue !== null && cellValue !== undefined
|
|
244
|
-
? String(cellValue)
|
|
245
|
-
: undefined;
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
// User field: deserialize using the matching FieldDefinition
|
|
249
|
-
const fieldDef = useMap ? fieldMap.get(col) : fields.find((f) => f.name === col);
|
|
250
|
-
if (fieldDef) {
|
|
251
|
-
entity[col] = deserializeValue(cellValue, fieldDef);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
// Unknown column — keep raw value (defensive)
|
|
255
|
-
entity[col] = cellValue;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return entity;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Public serialization utility class.
|
|
263
|
-
*
|
|
264
|
-
* Wraps five static methods that handle the Entity ←→ row conversion:
|
|
265
|
-
* - serializeValue / deserializeValue — single-field level
|
|
266
|
-
* - buildHeaders — construct the header row
|
|
267
|
-
* - entityToRow / rowToEntity — full entity conversion
|
|
268
|
-
*/
|
|
269
|
-
export class Serialization {
|
|
270
|
-
}
|
|
271
|
-
/** Serialize a single field value for cell storage. */
|
|
272
|
-
Serialization.serializeValue = serializeValue;
|
|
273
|
-
/** Deserialize a single cell value back to a JS value. */
|
|
274
|
-
Serialization.deserializeValue = deserializeValue;
|
|
275
|
-
/** Build the full header row (system + user columns). */
|
|
276
|
-
Serialization.buildHeaders = buildHeaders;
|
|
277
|
-
/** Convert an entity to a sheet row array. */
|
|
278
|
-
Serialization.entityToRow = entityToRow;
|
|
279
|
-
/** Convert a sheet row array to an entity object. */
|
|
280
|
-
Serialization.rowToEntity = rowToEntity;
|
|
281
|
-
//# sourceMappingURL=Serialization.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Serialization.js","sourceRoot":"","sources":["../../../src/utils/Serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,cAAc,CAAC,KAAc,EAAE,QAAyB;IAC/D,gCAAgC;IAChC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAErD,+BAA+B;IAC/B,IAA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,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight, globally togglable logger for SheetORM internals.
|
|
3
|
-
*
|
|
4
|
-
* When {@link verbose} is `true`, every log call is forwarded to either
|
|
5
|
-
* the Google Apps Script `Logger` (when running inside GAS) or `console.log`
|
|
6
|
-
* (when running in Node / Jest / browser).
|
|
7
|
-
*
|
|
8
|
-
* Usage from a GAS script:
|
|
9
|
-
* ```ts
|
|
10
|
-
* SheetORM.SheetOrmLogger.verbose = true;
|
|
11
|
-
* GasEntrypoints.runBenchmark();
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* All SheetORM subsystems (GoogleSheetAdapter, SheetRepository, IndexStore,
|
|
15
|
-
* MemoryCache) emit structured log lines through this class, e.g.:
|
|
16
|
-
* `[Cache] HIT "tbl_Cars"`, `[Adapter] getAllData "idx_Cars" → 42 rows`.
|
|
17
|
-
*/
|
|
18
|
-
export declare class SheetOrmLogger {
|
|
19
|
-
/**
|
|
20
|
-
* Master switch for verbose logging.
|
|
21
|
-
* Set to `true` before any ORM operation to capture detailed traces.
|
|
22
|
-
*/
|
|
23
|
-
static verbose: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Emit a log message if verbose mode is enabled.
|
|
26
|
-
*
|
|
27
|
-
* @param msg - Human-readable message (typically prefixed with a subsystem tag).
|
|
28
|
-
*/
|
|
29
|
-
static log(msg: string): void;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=SheetOrmLogger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SheetOrmLogger.d.ts","sourceRoot":"","sources":["../../../src/utils/SheetOrmLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAc;IACzB;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,CAAS;IAEhC;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAW9B"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight, globally togglable logger for SheetORM internals.
|
|
3
|
-
*
|
|
4
|
-
* When {@link verbose} is `true`, every log call is forwarded to either
|
|
5
|
-
* the Google Apps Script `Logger` (when running inside GAS) or `console.log`
|
|
6
|
-
* (when running in Node / Jest / browser).
|
|
7
|
-
*
|
|
8
|
-
* Usage from a GAS script:
|
|
9
|
-
* ```ts
|
|
10
|
-
* SheetORM.SheetOrmLogger.verbose = true;
|
|
11
|
-
* GasEntrypoints.runBenchmark();
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* All SheetORM subsystems (GoogleSheetAdapter, SheetRepository, IndexStore,
|
|
15
|
-
* MemoryCache) emit structured log lines through this class, e.g.:
|
|
16
|
-
* `[Cache] HIT "tbl_Cars"`, `[Adapter] getAllData "idx_Cars" → 42 rows`.
|
|
17
|
-
*/
|
|
18
|
-
export class SheetOrmLogger {
|
|
19
|
-
/**
|
|
20
|
-
* Emit a log message if verbose mode is enabled.
|
|
21
|
-
*
|
|
22
|
-
* @param msg - Human-readable message (typically prefixed with a subsystem tag).
|
|
23
|
-
*/
|
|
24
|
-
static log(msg) {
|
|
25
|
-
// Short-circuit when verbose logging is off (zero overhead in production)
|
|
26
|
-
if (!SheetOrmLogger.verbose)
|
|
27
|
-
return;
|
|
28
|
-
// Use GAS Logger when available, fall back to console.log in test / Node environments
|
|
29
|
-
if (typeof Logger !== "undefined" && typeof Logger.log === "function") {
|
|
30
|
-
Logger.log(msg);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
console.log(msg);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Master switch for verbose logging.
|
|
39
|
-
* Set to `true` before any ORM operation to capture detailed traces.
|
|
40
|
-
*/
|
|
41
|
-
SheetOrmLogger.verbose = false;
|
|
42
|
-
//# sourceMappingURL=SheetOrmLogger.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SheetOrmLogger.js","sourceRoot":"","sources":["../../../src/utils/SheetOrmLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,cAAc;IAOzB;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,GAAW;QACpB,0EAA0E;QAC1E,IAAI,CAAC,cAAc,CAAC,OAAO;YAAE,OAAO;QAEpC,sFAAsF;QACtF,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;YACtE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;;AArBD;;;GAGG;AACI,sBAAO,GAAY,KAAK,CAAC"}
|
package/dist/npm/utils/Uuid.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* UUID v4 generation with a three-tier fallback strategy:
|
|
3
|
-
*
|
|
4
|
-
* 1. **GAS Utilities.getUuid()** — native, crypto-safe, fastest in Apps Script.
|
|
5
|
-
* 2. **Web Crypto API (globalThis.crypto)** — available in Node 19+, browsers,
|
|
6
|
-
* Deno, Bun, and other modern runtimes.
|
|
7
|
-
* 3. **Math.random()** — last resort; not cryptographically secure but
|
|
8
|
-
* adequate for non-security-critical record identifiers in dev/test.
|
|
9
|
-
*
|
|
10
|
-
* All generated UUIDs conform to RFC 4122 v4 (random).
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Generate a RFC 4122 v4 (random) UUID string.
|
|
14
|
-
*
|
|
15
|
-
* @returns A lowercase UUID in the canonical `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` format.
|
|
16
|
-
*/
|
|
17
|
-
declare function generateUUID(): string;
|
|
18
|
-
/**
|
|
19
|
-
* Public UUID utility class.
|
|
20
|
-
*
|
|
21
|
-
* Exposes a single static method `generate()` that returns a new UUID v4 string.
|
|
22
|
-
* Wrapped in a class to follow the SheetORM one-export-per-file convention.
|
|
23
|
-
*/
|
|
24
|
-
export declare class Uuid {
|
|
25
|
-
/** Generate a new RFC 4122 v4 UUID string. */
|
|
26
|
-
static generate: typeof generateUUID;
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=Uuid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Uuid.d.ts","sourceRoot":"","sources":["../../../src/utils/Uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoBH;;;;GAIG;AACH,iBAAS,YAAY,IAAI,MAAM,CAqD9B;AAED;;;;;GAKG;AACH,qBAAa,IAAI;IACf,8CAA8C;IAC9C,MAAM,CAAC,QAAQ,sBAAgB;CAChC"}
|
package/dist/npm/utils/Uuid.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* UUID v4 generation with a three-tier fallback strategy:
|
|
3
|
-
*
|
|
4
|
-
* 1. **GAS Utilities.getUuid()** — native, crypto-safe, fastest in Apps Script.
|
|
5
|
-
* 2. **Web Crypto API (globalThis.crypto)** — available in Node 19+, browsers,
|
|
6
|
-
* Deno, Bun, and other modern runtimes.
|
|
7
|
-
* 3. **Math.random()** — last resort; not cryptographically secure but
|
|
8
|
-
* adequate for non-security-critical record identifiers in dev/test.
|
|
9
|
-
*
|
|
10
|
-
* All generated UUIDs conform to RFC 4122 v4 (random).
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Pre-computed lookup table mapping byte values (0–255) to their two-character
|
|
14
|
-
* hexadecimal representations. Avoids per-byte toString(16) + padStart calls
|
|
15
|
-
* during UUID formatting.
|
|
16
|
-
*/
|
|
17
|
-
const HEX = new Array(256);
|
|
18
|
-
for (let i = 0; i < 256; i++) {
|
|
19
|
-
// (i + 0x100) produces a 3-char hex string; substring(1) drops the leading "1"
|
|
20
|
-
HEX[i] = (i + 0x100).toString(16).substring(1);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Generate a RFC 4122 v4 (random) UUID string.
|
|
24
|
-
*
|
|
25
|
-
* @returns A lowercase UUID in the canonical `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` format.
|
|
26
|
-
*/
|
|
27
|
-
function generateUUID() {
|
|
28
|
-
// --- Tier 1: GAS native UUID ---
|
|
29
|
-
// Google Apps Script V8 runtime exposes Utilities.getUuid(), which delegates
|
|
30
|
-
// to Java's java.util.UUID.randomUUID() — crypto-safe and zero-overhead.
|
|
31
|
-
if (typeof Utilities !== "undefined" && typeof Utilities.getUuid === "function") {
|
|
32
|
-
return Utilities.getUuid();
|
|
33
|
-
}
|
|
34
|
-
// --- Tier 2 & 3: manual RFC 4122 v4 construction ---
|
|
35
|
-
// Allocate 16 random bytes (128 bits); 6 bits are then overwritten for version/variant.
|
|
36
|
-
const r = new Uint8Array(16);
|
|
37
|
-
// Attempt to fill with crypto-safe random values via Web Crypto API
|
|
38
|
-
const globalHost = globalThis;
|
|
39
|
-
const g = typeof globalThis !== "undefined" ? globalHost.crypto : undefined;
|
|
40
|
-
if (g && typeof g.getRandomValues === "function") {
|
|
41
|
-
// Tier 2: Web Crypto (Node 19+, browsers, Deno)
|
|
42
|
-
g.getRandomValues(r);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
// Tier 3: Math.random fallback (non-crypto, dev/test only)
|
|
46
|
-
for (let i = 0; i < 16; i++) {
|
|
47
|
-
r[i] = (Math.random() * 256) | 0;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Set the version nibble (bits 48–51) to 0100 → UUID version 4
|
|
51
|
-
r[6] = (r[6] & 0x0f) | 0x40;
|
|
52
|
-
// Set the variant bits (bits 64–65) to 10 → RFC 4122 variant
|
|
53
|
-
r[8] = (r[8] & 0x3f) | 0x80;
|
|
54
|
-
// Format as canonical UUID string: 8-4-4-4-12 hexadecimal characters
|
|
55
|
-
return (HEX[r[0]] +
|
|
56
|
-
HEX[r[1]] +
|
|
57
|
-
HEX[r[2]] +
|
|
58
|
-
HEX[r[3]] +
|
|
59
|
-
"-" +
|
|
60
|
-
HEX[r[4]] +
|
|
61
|
-
HEX[r[5]] +
|
|
62
|
-
"-" +
|
|
63
|
-
HEX[r[6]] +
|
|
64
|
-
HEX[r[7]] +
|
|
65
|
-
"-" +
|
|
66
|
-
HEX[r[8]] +
|
|
67
|
-
HEX[r[9]] +
|
|
68
|
-
"-" +
|
|
69
|
-
HEX[r[10]] +
|
|
70
|
-
HEX[r[11]] +
|
|
71
|
-
HEX[r[12]] +
|
|
72
|
-
HEX[r[13]] +
|
|
73
|
-
HEX[r[14]] +
|
|
74
|
-
HEX[r[15]]);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Public UUID utility class.
|
|
78
|
-
*
|
|
79
|
-
* Exposes a single static method `generate()` that returns a new UUID v4 string.
|
|
80
|
-
* Wrapped in a class to follow the SheetORM one-export-per-file convention.
|
|
81
|
-
*/
|
|
82
|
-
export class Uuid {
|
|
83
|
-
}
|
|
84
|
-
/** Generate a new RFC 4122 v4 UUID string. */
|
|
85
|
-
Uuid.generate = generateUUID;
|
|
86
|
-
//# sourceMappingURL=Uuid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Uuid.js","sourceRoot":"","sources":["../../../src/utils/Uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;GAIG;AACH,MAAM,GAAG,GAAa,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;IAC7B,+EAA+E;IAC/E,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,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