@elaraai/e3 1.0.98 → 1.0.100
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/README.md +4 -5
- package/dist/src/browser.d.ts +2 -0
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +6 -0
- package/dist/src/browser.js.map +1 -1
- package/dist/src/environment-capture.d.ts +21 -0
- package/dist/src/environment-capture.d.ts.map +1 -1
- package/dist/src/environment-capture.js +48 -0
- package/dist/src/environment-capture.js.map +1 -1
- package/dist/src/export.d.ts +10 -5
- package/dist/src/export.d.ts.map +1 -1
- package/dist/src/export.js +31 -47
- package/dist/src/export.js.map +1 -1
- package/dist/src/export.spec.js +27 -16
- package/dist/src/export.spec.js.map +1 -1
- package/dist/src/function.d.ts.map +1 -1
- package/dist/src/function.js.map +1 -1
- package/dist/src/functions-cache.d.ts +60 -0
- package/dist/src/functions-cache.d.ts.map +1 -0
- package/dist/src/functions-cache.js +165 -0
- package/dist/src/functions-cache.js.map +1 -0
- package/dist/src/functions-link.spec.js +191 -12
- package/dist/src/functions-link.spec.js.map +1 -1
- package/dist/src/functions-resolve.d.ts +52 -23
- package/dist/src/functions-resolve.d.ts.map +1 -1
- package/dist/src/functions-resolve.js +244 -96
- package/dist/src/functions-resolve.js.map +1 -1
- package/dist/src/index.d.ts +8 -61
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal.d.ts +53 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/src/internal.js +29 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/lazy-build.d.ts +25 -0
- package/dist/src/lazy-build.d.ts.map +1 -0
- package/dist/src/lazy-build.js +56 -0
- package/dist/src/lazy-build.js.map +1 -0
- package/dist/src/lazy-build.spec.d.ts +6 -0
- package/dist/src/lazy-build.spec.d.ts.map +1 -0
- package/dist/src/lazy-build.spec.js +153 -0
- package/dist/src/lazy-build.spec.js.map +1 -0
- package/dist/src/migration.d.ts +20 -163
- package/dist/src/migration.d.ts.map +1 -1
- package/dist/src/migration.js +37 -34
- package/dist/src/migration.js.map +1 -1
- package/dist/src/migration.spec.js +83 -78
- package/dist/src/migration.spec.js.map +1 -1
- package/dist/src/mutation-programs.spec.js +211 -118
- package/dist/src/mutation-programs.spec.js.map +1 -1
- package/dist/src/mutation.d.ts +37 -141
- package/dist/src/mutation.d.ts.map +1 -1
- package/dist/src/mutation.js +66 -28
- package/dist/src/mutation.js.map +1 -1
- package/dist/src/open-beast-link.spec.js +1 -1
- package/dist/src/open-beast-link.spec.js.map +1 -1
- package/dist/src/output.js.map +1 -1
- package/dist/src/package.d.ts +2 -38
- package/dist/src/package.d.ts.map +1 -1
- package/dist/src/package.js +42 -175
- package/dist/src/package.js.map +1 -1
- package/dist/src/record-area.d.ts +49 -37
- package/dist/src/record-area.d.ts.map +1 -1
- package/dist/src/record-area.js +211 -131
- package/dist/src/record-area.js.map +1 -1
- package/dist/src/record-area.spec.js +79 -62
- package/dist/src/record-area.spec.js.map +1 -1
- package/dist/src/record-arguments.d.ts +55 -0
- package/dist/src/record-arguments.d.ts.map +1 -0
- package/dist/src/record-arguments.js +72 -0
- package/dist/src/record-arguments.js.map +1 -0
- package/dist/src/record-builders.d.ts +547 -0
- package/dist/src/record-builders.d.ts.map +1 -0
- package/dist/src/record-builders.js +112 -0
- package/dist/src/record-builders.js.map +1 -0
- package/dist/src/record-declared.spec.d.ts +6 -0
- package/dist/src/record-declared.spec.d.ts.map +1 -0
- package/dist/src/record-declared.spec.js +251 -0
- package/dist/src/record-declared.spec.js.map +1 -0
- package/dist/src/record-guards.d.ts +114 -1
- package/dist/src/record-guards.d.ts.map +1 -1
- package/dist/src/record-guards.js +153 -2
- package/dist/src/record-guards.js.map +1 -1
- package/dist/src/record-index.d.ts +128 -350
- package/dist/src/record-index.d.ts.map +1 -1
- package/dist/src/record-index.js +44 -481
- package/dist/src/record-index.js.map +1 -1
- package/dist/src/record-index.spec.js +124 -90
- package/dist/src/record-index.spec.js.map +1 -1
- package/dist/src/record-interval.d.ts +57 -36
- package/dist/src/record-interval.d.ts.map +1 -1
- package/dist/src/record-interval.js +136 -94
- package/dist/src/record-interval.js.map +1 -1
- package/dist/src/record-interval.spec.js +48 -27
- package/dist/src/record-interval.spec.js.map +1 -1
- package/dist/src/record-keys.d.ts +146 -0
- package/dist/src/record-keys.d.ts.map +1 -0
- package/dist/src/record-keys.js +178 -0
- package/dist/src/record-keys.js.map +1 -0
- package/dist/src/record-nested-programs.d.ts +1457 -0
- package/dist/src/record-nested-programs.d.ts.map +1 -0
- package/dist/src/record-nested-programs.js +1974 -0
- package/dist/src/record-nested-programs.js.map +1 -0
- package/dist/src/record-nested.d.ts +284 -0
- package/dist/src/record-nested.d.ts.map +1 -0
- package/dist/src/record-nested.js +304 -0
- package/dist/src/record-nested.js.map +1 -0
- package/dist/src/record-nested.spec.d.ts +6 -0
- package/dist/src/record-nested.spec.d.ts.map +1 -0
- package/dist/src/record-nested.spec.js +1032 -0
- package/dist/src/record-nested.spec.js.map +1 -0
- package/dist/src/record-patches.d.ts +25 -0
- package/dist/src/record-patches.d.ts.map +1 -0
- package/dist/src/record-patches.js +27 -0
- package/dist/src/record-patches.js.map +1 -0
- package/dist/src/record-programs.d.ts +192 -26
- package/dist/src/record-programs.d.ts.map +1 -1
- package/dist/src/record-programs.js +858 -350
- package/dist/src/record-programs.js.map +1 -1
- package/dist/src/record-programs.spec.d.ts +6 -0
- package/dist/src/record-programs.spec.d.ts.map +1 -0
- package/dist/src/record-programs.spec.js +242 -0
- package/dist/src/record-programs.spec.js.map +1 -0
- package/dist/src/record-series.d.ts +101 -97
- package/dist/src/record-series.d.ts.map +1 -1
- package/dist/src/record-series.js +198 -149
- package/dist/src/record-series.js.map +1 -1
- package/dist/src/record-series.spec.js +241 -120
- package/dist/src/record-series.spec.js.map +1 -1
- package/dist/src/record-tiles.d.ts +328 -37
- package/dist/src/record-tiles.d.ts.map +1 -1
- package/dist/src/record-tiles.js +289 -100
- package/dist/src/record-tiles.js.map +1 -1
- package/dist/src/record.d.ts +66 -12
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/record.js +103 -34
- package/dist/src/record.js.map +1 -1
- package/dist/src/record.spec.js +48 -63
- package/dist/src/record.spec.js.map +1 -1
- package/dist/src/task.d.ts.map +1 -1
- package/dist/src/task.js +4 -1
- package/dist/src/task.js.map +1 -1
- package/dist/src/types.d.ts +103 -37
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +7 -3
package/dist/src/index.js
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
import { input } from './input.js';
|
|
6
6
|
import { record } from './record.js';
|
|
7
7
|
import { mutation } from './mutation.js';
|
|
8
|
-
import { migration } from './migration.js';
|
|
9
|
-
import { recordIndex } from './record-index.js';
|
|
10
8
|
import { task, customTask, streamTask, partition } from './task.js';
|
|
11
9
|
import { output } from './output.js';
|
|
12
10
|
import { function_ } from './function.js';
|
|
@@ -22,8 +20,6 @@ const e3 = {
|
|
|
22
20
|
input,
|
|
23
21
|
record,
|
|
24
22
|
mutation,
|
|
25
|
-
migration,
|
|
26
|
-
recordIndex,
|
|
27
23
|
task,
|
|
28
24
|
customTask,
|
|
29
25
|
streamTask,
|
|
@@ -35,7 +31,7 @@ const e3 = {
|
|
|
35
31
|
};
|
|
36
32
|
export default e3;
|
|
37
33
|
// Also export individual functions for tree-shaking
|
|
38
|
-
export { input, record, mutation,
|
|
34
|
+
export { input, record, mutation, task, customTask, streamTask, partition, output, function_, package_ as package, export_ as export };
|
|
39
35
|
// Singleton tree definitions
|
|
40
36
|
export { inputsTree } from './input.js';
|
|
41
37
|
export { recordsTree } from './record.js';
|
|
@@ -47,7 +43,6 @@ export { sha256File, sha256Bytes, hashToPath } from './sha256.js';
|
|
|
47
43
|
export { readDatasetFileHeader, readDatasetFileType, DatasetFileTypeMismatchError, } from './dataset-file.js';
|
|
48
44
|
export { DatasetSourceType } from './input.js';
|
|
49
45
|
export { addObject } from './export.js';
|
|
50
|
-
export { indexBuildProgram, buildMutationProgram, migrationProgram, summaryMergeProgram, deltaTargets, indexEntryKeyType } from './record-programs.js';
|
|
51
|
-
export { RECORD_TILES, MAX_EVENT_TILES,
|
|
52
|
-
export { TILE_FIELD } from './record-series.js';
|
|
46
|
+
export { indexBuildProgram, buildMutationProgram, migrationProgram, summaryMergeProgram, deltaTargets, indexEntryKeyType, builtIndex, indexMaintenance } from './record-programs.js';
|
|
47
|
+
export { RECORD_TILES, MAX_EVENT_TILES, SHORTEST_MS, TileShareType, TileFilingType, } from './record-tiles.js';
|
|
53
48
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAiC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AY,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,GAC1E,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/** The start of the tile of a level holding an instant: `(level, at) → its start`. */
|
|
6
|
+
export declare const tileStart: import("@elaraai/east").CallableFunctionExpr<[import("@elaraai/east").VariantType<{
|
|
7
|
+
readonly day: import("@elaraai/east").NullType;
|
|
8
|
+
readonly week: import("@elaraai/east").NullType;
|
|
9
|
+
readonly month: import("@elaraai/east").NullType;
|
|
10
|
+
readonly quarter: import("@elaraai/east").NullType;
|
|
11
|
+
readonly year: import("@elaraai/east").NullType;
|
|
12
|
+
}>, import("@elaraai/east").DateTimeType], import("@elaraai/east").DateTimeType>;
|
|
13
|
+
/** The start of the tile after one, for a tile's start: `(level, start) → the next tile's start`. */
|
|
14
|
+
export declare const tileNext: import("@elaraai/east").CallableFunctionExpr<[import("@elaraai/east").VariantType<{
|
|
15
|
+
readonly day: import("@elaraai/east").NullType;
|
|
16
|
+
readonly week: import("@elaraai/east").NullType;
|
|
17
|
+
readonly month: import("@elaraai/east").NullType;
|
|
18
|
+
readonly quarter: import("@elaraai/east").NullType;
|
|
19
|
+
readonly year: import("@elaraai/east").NullType;
|
|
20
|
+
}>, import("@elaraai/east").DateTimeType], import("@elaraai/east").DateTimeType>;
|
|
21
|
+
/**
|
|
22
|
+
* The tiles of a level an event touches, and its share of each:
|
|
23
|
+
* `(level, start, end, what) → each tile it touches, in order, and the
|
|
24
|
+
* milliseconds of it the event covers`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const tileShares: import("@elaraai/east").CallableFunctionExpr<[import("@elaraai/east").VariantType<{
|
|
27
|
+
readonly day: import("@elaraai/east").NullType;
|
|
28
|
+
readonly week: import("@elaraai/east").NullType;
|
|
29
|
+
readonly month: import("@elaraai/east").NullType;
|
|
30
|
+
readonly quarter: import("@elaraai/east").NullType;
|
|
31
|
+
readonly year: import("@elaraai/east").NullType;
|
|
32
|
+
}>, import("@elaraai/east").DateTimeType, import("@elaraai/east").DateTimeType, import("@elaraai/east").StringType], import("@elaraai/east").ArrayType<import("@elaraai/east").StructType<{
|
|
33
|
+
readonly tile: import("@elaraai/east").DateTimeType;
|
|
34
|
+
readonly ms: import("@elaraai/east").IntegerType;
|
|
35
|
+
}>>>;
|
|
36
|
+
/** Where a series index files an event: `(tile, start, end, what) → each place it is filed, in order`. */
|
|
37
|
+
export declare const eventFilings: import("@elaraai/east").CallableFunctionExpr<[import("@elaraai/east").VariantType<{
|
|
38
|
+
readonly day: import("@elaraai/east").NullType;
|
|
39
|
+
readonly week: import("@elaraai/east").NullType;
|
|
40
|
+
readonly month: import("@elaraai/east").NullType;
|
|
41
|
+
readonly quarter: import("@elaraai/east").NullType;
|
|
42
|
+
readonly year: import("@elaraai/east").NullType;
|
|
43
|
+
}>, import("@elaraai/east").DateTimeType, import("@elaraai/east").DateTimeType, import("@elaraai/east").StringType], import("@elaraai/east").ArrayType<import("@elaraai/east").StructType<{
|
|
44
|
+
readonly level: import("@elaraai/east").VariantType<{
|
|
45
|
+
readonly day: import("@elaraai/east").NullType;
|
|
46
|
+
readonly week: import("@elaraai/east").NullType;
|
|
47
|
+
readonly month: import("@elaraai/east").NullType;
|
|
48
|
+
readonly quarter: import("@elaraai/east").NullType;
|
|
49
|
+
readonly year: import("@elaraai/east").NullType;
|
|
50
|
+
}>;
|
|
51
|
+
readonly tile: import("@elaraai/east").DateTimeType;
|
|
52
|
+
}>>>;
|
|
53
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,sFAAsF;AACtF,eAAO,MAAM,SAAS;;;;;;gFAAqB,CAAC;AAE5C,qGAAqG;AACrG,eAAO,MAAM,QAAQ;;;;;;gFAAoB,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;;;;;;;IAAsB,CAAC;AAE9C,0GAA0G;AAC1G,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;IAAwB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* `@elaraai/e3/internal` — the record tiles' East functions, for the packages
|
|
7
|
+
* that check their own tiling against e3's (e3-ui's record bindings).
|
|
8
|
+
*
|
|
9
|
+
* Not an API for solutions, and not held stable: a solution files its events
|
|
10
|
+
* through a record's indexes. The main entry builds none of the SDK's East
|
|
11
|
+
* functions when it is imported (#1466); importing this entry builds these
|
|
12
|
+
* four.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
import { TILE_FNS } from './record-tiles.js';
|
|
17
|
+
/** The start of the tile of a level holding an instant: `(level, at) → its start`. */
|
|
18
|
+
export const tileStart = TILE_FNS.tileStart;
|
|
19
|
+
/** The start of the tile after one, for a tile's start: `(level, start) → the next tile's start`. */
|
|
20
|
+
export const tileNext = TILE_FNS.tileNext;
|
|
21
|
+
/**
|
|
22
|
+
* The tiles of a level an event touches, and its share of each:
|
|
23
|
+
* `(level, start, end, what) → each tile it touches, in order, and the
|
|
24
|
+
* milliseconds of it the event covers`.
|
|
25
|
+
*/
|
|
26
|
+
export const tileShares = TILE_FNS.tileShares;
|
|
27
|
+
/** Where a series index files an event: `(tile, start, end, what) → each place it is filed, in order`. */
|
|
28
|
+
export const eventFilings = TILE_FNS.eventFilings;
|
|
29
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,sFAAsF;AACtF,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;AAE5C,qGAAqG;AACrG,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;AAE9C,0GAA0G;AAC1G,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Makes each getter of an object build its value the first time it is read,
|
|
7
|
+
* and keep it.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* A value is built with no location captured, under a source map of its own:
|
|
11
|
+
* as an installed SDK built it at import, whose frames East never captures,
|
|
12
|
+
* since they sit under `node_modules`, while no other function was being
|
|
13
|
+
* built. So a program holds the bytes it held then, whoever reads one of
|
|
14
|
+
* these first — never the reader's frames, and, in this repository, never
|
|
15
|
+
* the SDK's own.
|
|
16
|
+
*
|
|
17
|
+
* A property that is no getter stays as it is.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam L - The object, its values as getters
|
|
20
|
+
* @param library - The object, each of whose getters builds one value
|
|
21
|
+
* @returns The object, each getter now building its value once, the first
|
|
22
|
+
* time it is read, after which the value is a property of its own
|
|
23
|
+
*/
|
|
24
|
+
export declare function lazyBuilds<L extends object>(library: L): L;
|
|
25
|
+
//# sourceMappingURL=lazy-build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-build.d.ts","sourceRoot":"","sources":["../../src/lazy-build.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAe1D"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The SDK's own East functions, each built the first time it is read (#1466).
|
|
7
|
+
*
|
|
8
|
+
* The record modules hold the East functions their indexes' and writes'
|
|
9
|
+
* programs call. Built at import, they cost every process that imports
|
|
10
|
+
* `@elaraai/e3` — every CLI run, every server start, every spec — some sixty
|
|
11
|
+
* builds and the TypeScript compiler, which the first build in a process
|
|
12
|
+
* loads, whether the process reads a record or not. Each module keeps them as
|
|
13
|
+
* the getters of one object instead, which {@link lazyBuilds} has build its
|
|
14
|
+
* function the first time it is read, as East builds its own libraries
|
|
15
|
+
* (#1127).
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { SourceMap, with_source_map, withLocationCapture } from '@elaraai/east';
|
|
20
|
+
/**
|
|
21
|
+
* Makes each getter of an object build its value the first time it is read,
|
|
22
|
+
* and keep it.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* A value is built with no location captured, under a source map of its own:
|
|
26
|
+
* as an installed SDK built it at import, whose frames East never captures,
|
|
27
|
+
* since they sit under `node_modules`, while no other function was being
|
|
28
|
+
* built. So a program holds the bytes it held then, whoever reads one of
|
|
29
|
+
* these first — never the reader's frames, and, in this repository, never
|
|
30
|
+
* the SDK's own.
|
|
31
|
+
*
|
|
32
|
+
* A property that is no getter stays as it is.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam L - The object, its values as getters
|
|
35
|
+
* @param library - The object, each of whose getters builds one value
|
|
36
|
+
* @returns The object, each getter now building its value once, the first
|
|
37
|
+
* time it is read, after which the value is a property of its own
|
|
38
|
+
*/
|
|
39
|
+
export function lazyBuilds(library) {
|
|
40
|
+
for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(library))) {
|
|
41
|
+
const build = descriptor.get;
|
|
42
|
+
if (build === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
Object.defineProperty(library, name, {
|
|
45
|
+
enumerable: descriptor.enumerable ?? true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
get: () => {
|
|
48
|
+
const built = with_source_map(new SourceMap(), () => withLocationCapture(false, () => build.call(library)));
|
|
49
|
+
Object.defineProperty(library, name, { value: built, enumerable: descriptor.enumerable ?? true, writable: false, configurable: false });
|
|
50
|
+
return built;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return library;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=lazy-build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-build.js","sourceRoot":"","sources":["../../src/lazy-build.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAAmB,OAAU;IACrD,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAC3F,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC;QAC7B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE;YACnC,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,IAAI;YACzC,YAAY,EAAE,IAAI;YAClB,GAAG,EAAE,GAAG,EAAE;gBACR,MAAM,KAAK,GAAY,eAAe,CAAC,IAAI,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACrH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;gBACxI,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-build.spec.d.ts","sourceRoot":"","sources":["../../src/lazy-build.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* {@link lazyBuilds} (#1466): each getter's value built once, the first time
|
|
7
|
+
* it is read, with no location captured — so a function's IR is the same
|
|
8
|
+
* whoever reads it first — and a property that is no getter left as it is.
|
|
9
|
+
* And the SDK's own East functions, kept so: importing the SDK builds none of
|
|
10
|
+
* them and loads no TypeScript, each is built with no location, as an
|
|
11
|
+
* installed SDK builds it, and `@elaraai/e3/internal` gives the four the UI
|
|
12
|
+
* checks its tiles against.
|
|
13
|
+
*/
|
|
14
|
+
import { describe, it } from 'node:test';
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
import { spawnSync } from 'node:child_process';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { DateTimeType, East, IntegerType, decodeEastIR, encodeEastIR, sha256Hex, variant } from '@elaraai/east';
|
|
19
|
+
import { RecordLevelType } from '@elaraai/e3-types';
|
|
20
|
+
import { lazyBuilds } from './lazy-build.js';
|
|
21
|
+
import { AREA_FNS } from './record-area.js';
|
|
22
|
+
import { INTERVAL_FNS } from './record-interval.js';
|
|
23
|
+
import { KIT_CALLED, KIT_UNCALLED, NESTED_FNS } from './record-nested-programs.js';
|
|
24
|
+
import { PROGRAM_FNS } from './record-programs.js';
|
|
25
|
+
import { SERIES_FNS } from './record-series.js';
|
|
26
|
+
import { TILE_FNS } from './record-tiles.js';
|
|
27
|
+
import { eventFilings, tileNext, tileShares, tileStart } from './internal.js';
|
|
28
|
+
describe('lazyBuilds', () => {
|
|
29
|
+
it('builds each getter\'s value once, the first time it is read, and leaves a property that is no getter as it is', () => {
|
|
30
|
+
let builds = 0;
|
|
31
|
+
const library = lazyBuilds({
|
|
32
|
+
kept: 1,
|
|
33
|
+
get built() {
|
|
34
|
+
builds++;
|
|
35
|
+
return { at: builds };
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
assert.equal(builds, 0, 'nothing is built until it is read');
|
|
39
|
+
const first = library.built;
|
|
40
|
+
assert.equal(library.built, first);
|
|
41
|
+
assert.equal(builds, 1, 'built once');
|
|
42
|
+
assert.equal(library.kept, 1);
|
|
43
|
+
assert.deepEqual(Object.keys(library), ['kept', 'built'], 'both stay enumerable, in order');
|
|
44
|
+
const descriptor = Object.getOwnPropertyDescriptor(library, 'built');
|
|
45
|
+
assert.equal(descriptor?.get, undefined, 'once built, the value is a property of its own');
|
|
46
|
+
assert.equal(descriptor?.value, first);
|
|
47
|
+
});
|
|
48
|
+
it('builds an East function with no location captured: its IR is the same read first at the top or inside a caller\'s body', () => {
|
|
49
|
+
const make = () => lazyBuilds({
|
|
50
|
+
get double() {
|
|
51
|
+
return East.function([IntegerType], IntegerType, ($, n) => {
|
|
52
|
+
const twice = $.let(n.add(n));
|
|
53
|
+
return twice;
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const irOf = (fn) => sha256Hex(encodeEastIR(fn.toIR()));
|
|
58
|
+
const atTop = make();
|
|
59
|
+
const top = irOf(atTop.double);
|
|
60
|
+
const inCaller = make();
|
|
61
|
+
East.function([IntegerType], IntegerType, ($, n) => {
|
|
62
|
+
const double = $.const(inCaller.double);
|
|
63
|
+
return double(n);
|
|
64
|
+
});
|
|
65
|
+
assert.equal(irOf(inCaller.double), top, 'the caller\'s frames and names never reach it');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
/** Each object of the SDK's own East functions, by the module that holds it. */
|
|
69
|
+
const HOLDERS = {
|
|
70
|
+
'record-area.js': { AREA_FNS },
|
|
71
|
+
'record-interval.js': { INTERVAL_FNS },
|
|
72
|
+
'record-nested-programs.js': { KIT_CALLED, KIT_UNCALLED, NESTED_FNS },
|
|
73
|
+
'record-programs.js': { PROGRAM_FNS },
|
|
74
|
+
'record-series.js': { SERIES_FNS },
|
|
75
|
+
'record-tiles.js': { TILE_FNS },
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Run in a process of its own: imports the SDK with `East.function` counted,
|
|
79
|
+
* then names, of each holder, the functions already built, and reads one twice.
|
|
80
|
+
*/
|
|
81
|
+
const IMPORT_PROBE = `
|
|
82
|
+
import { createRequire } from 'node:module';
|
|
83
|
+
const { East } = await import('@elaraai/east');
|
|
84
|
+
let built = 0;
|
|
85
|
+
const build = East.function;
|
|
86
|
+
East.function = function (...args) { built += 1; return build.apply(this, args); };
|
|
87
|
+
const [index, holders] = process.argv.slice(1);
|
|
88
|
+
await import(index);
|
|
89
|
+
const atImport = built;
|
|
90
|
+
const typescript = Object.keys(createRequire(import.meta.url).cache).some((path) => /[\\\\/]typescript[\\\\/]/.test(path));
|
|
91
|
+
const read = {};
|
|
92
|
+
let tiles;
|
|
93
|
+
for (const [module, names] of Object.entries(JSON.parse(holders))) {
|
|
94
|
+
const loaded = await import(module);
|
|
95
|
+
for (const name of names) {
|
|
96
|
+
read[name] = Object.entries(Object.getOwnPropertyDescriptors(loaded[name])).filter(([, d]) => d.get === undefined).map(([key]) => key);
|
|
97
|
+
if (name === 'TILE_FNS') tiles = loaded[name];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const before = built;
|
|
101
|
+
const first = tiles.tileStart;
|
|
102
|
+
const once = built - before;
|
|
103
|
+
const again = tiles.tileStart === first ? built - before - once : -1;
|
|
104
|
+
console.log(JSON.stringify({ atImport, typescript, read, once, again }));
|
|
105
|
+
`;
|
|
106
|
+
describe('the SDK\'s own East functions', () => {
|
|
107
|
+
it('none is built, nor TypeScript loaded, when the SDK is imported; each is built the first time it is read, once', () => {
|
|
108
|
+
const modules = Object.fromEntries(Object.entries(HOLDERS).map(([module, holders]) => [new URL(module, import.meta.url).href, Object.keys(holders)]));
|
|
109
|
+
const run = spawnSync(process.execPath, ['--input-type=module', '-e', IMPORT_PROBE, new URL('index.js', import.meta.url).href, JSON.stringify(modules)], {
|
|
110
|
+
cwd: fileURLToPath(new URL('../..', import.meta.url)), encoding: 'utf8',
|
|
111
|
+
});
|
|
112
|
+
assert.equal(run.status, 0, run.stderr);
|
|
113
|
+
const result = JSON.parse(run.stdout);
|
|
114
|
+
assert.equal(result.atImport, 0, 'importing the SDK builds no East function');
|
|
115
|
+
assert.equal(result.typescript, false, 'nor loads TypeScript, which East loads for its first build');
|
|
116
|
+
const none = Object.fromEntries(Object.values(HOLDERS).flatMap((holders) => Object.keys(holders)).map((name) => [name, []]));
|
|
117
|
+
assert.deepEqual(result.read, none, 'no holder\'s function was read');
|
|
118
|
+
assert.ok(result.once > 0, 'reading a function builds it');
|
|
119
|
+
assert.equal(result.again, 0, 'reading it again gives the same function and builds nothing');
|
|
120
|
+
});
|
|
121
|
+
it('builds each with no location: its IR names no file, as an installed SDK builds it, whose frames East never captures', () => {
|
|
122
|
+
for (const holders of Object.values(HOLDERS)) {
|
|
123
|
+
for (const [holder, fns] of Object.entries(holders)) {
|
|
124
|
+
for (const [name, fn] of Object.entries(fns)) {
|
|
125
|
+
const files = fn.toIR().source_map.entries().flat().map((location) => location.filename);
|
|
126
|
+
assert.deepEqual(files, [], `${holder}.${name}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
it('`@elaraai/e3/internal` gives the four tile functions, each an East function to compile, call from another, or keep as IR', () => {
|
|
132
|
+
assert.equal(import.meta.resolve('@elaraai/e3/internal'), new URL('internal.js', import.meta.url).href, 'the package\'s entry is this module');
|
|
133
|
+
const month = variant('month', null);
|
|
134
|
+
const day = variant('day', null);
|
|
135
|
+
const at = new Date('2026-10-17T13:00:00.000Z');
|
|
136
|
+
assert.deepEqual(East.compile(tileStart, [])(month, at), new Date('2026-10-01T00:00:00.000Z'));
|
|
137
|
+
const following = East.function([RecordLevelType, DateTimeType], DateTimeType, ($, level, instant) => {
|
|
138
|
+
const start = $.const(tileStart);
|
|
139
|
+
const next = $.const(tileNext);
|
|
140
|
+
return next(level, start(level, instant));
|
|
141
|
+
});
|
|
142
|
+
assert.deepEqual(East.compile(following, [])(month, at), new Date('2026-11-01T00:00:00.000Z'), 'called from another function');
|
|
143
|
+
const shares = decodeEastIR(encodeEastIR(tileShares.toIR())).compile([]);
|
|
144
|
+
assert.deepEqual(shares(day, new Date('2026-10-17T12:00:00.000Z'), new Date('2026-10-18T06:00:00.000Z'), 'a job'), [
|
|
145
|
+
{ tile: new Date('2026-10-17T00:00:00.000Z'), ms: 43200000n },
|
|
146
|
+
{ tile: new Date('2026-10-18T00:00:00.000Z'), ms: 21600000n },
|
|
147
|
+
], 'kept as IR, encoded, decoded and compiled');
|
|
148
|
+
assert.deepEqual(East.compile(eventFilings, [])(day, new Date('2026-10-17T12:00:00.000Z'), new Date('2026-10-18T06:00:00.000Z'), 'a job'), [
|
|
149
|
+
{ level: day, tile: new Date('2026-10-17T00:00:00.000Z') },
|
|
150
|
+
], 'eighteen hours are filed under the day they start in');
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
//# sourceMappingURL=lazy-build.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-build.spec.js","sourceRoot":"","sources":["../../src/lazy-build.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAe,MAAM,eAAe,CAAC;AAC7H,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE9E,QAAQ,CAAC,YAAY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GAAG,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,EAAE,OAAO,CAAC,EAAE;YACjH,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,EAAE,EAAE,EAAE,SAAW,EAAE;YAC/D,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,EAAE,EAAE,EAAE,SAAW,EAAE;SAChE,EAAE,2CAA2C,CAAC,CAAC;QAChD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,EAAE,OAAO,CAAC,EAAE;YACzI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,0BAA0B,CAAC,EAAE;SAC3D,EAAE,sDAAsD,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/migration.d.ts
CHANGED
|
@@ -2,171 +2,28 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
* Migration definitions for e3 records: the steps a deploy runs over a
|
|
7
|
-
* workspace's state when a package changes a record's type, or its values.
|
|
8
|
-
*
|
|
9
|
-
* A record's migrations are one chain. Each step names the one before it with
|
|
10
|
-
* `after`, and `e3.package` folds the chain onto its record in order. A deploy
|
|
11
|
-
* runs the steps a workspace has not applied and records each by its name, so
|
|
12
|
-
* a step keeps its identity when its code moves or its package is re-exported.
|
|
13
|
-
*
|
|
14
|
-
* The three forms differ in what the author's function sees, and so in what a
|
|
15
|
-
* step costs: `e3.migration.value` the whole state, `e3.migration.rows` one
|
|
16
|
-
* row at a time, and `e3.migration.rekey` one row at a time under a new key.
|
|
17
|
-
* Each function is pure East for the reason a mutation's is: a step runs again
|
|
18
|
-
* in every workspace that has not applied it, a piece at a time, and must
|
|
19
|
-
* migrate every one the same way.
|
|
20
|
-
*/
|
|
21
|
-
import type { CallableFunctionExpr, EastType, FunctionExpr, StructType } from '@elaraai/east';
|
|
22
|
-
import { ArrayType, DictType, SetType } from '@elaraai/east';
|
|
5
|
+
import type { MigrationForm } from '@elaraai/e3-types';
|
|
23
6
|
import type { MigrationDef, RecordDef } from './types.js';
|
|
7
|
+
import { type IndexFunction } from './record-guards.js';
|
|
24
8
|
import { type FunctionRunner } from './runner.js';
|
|
25
9
|
/**
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* {@link rows} and {@link rekey} migrate a collection a piece at a time.
|
|
42
|
-
*
|
|
43
|
-
* The function must be pure, synchronous East, as a mutation's reducer is: a
|
|
44
|
-
* step runs again in every workspace that has not applied it. Its types are
|
|
45
|
-
* read off its signature, and its chain is checked where it is declared: the
|
|
46
|
-
* step it names as `after` must be a migration of the same record that leaves
|
|
47
|
-
* the record as this step's `Old`. `e3.package` checks that the record's last
|
|
48
|
-
* step leaves it as its declared type.
|
|
49
|
-
*
|
|
50
|
-
* @typeParam Name - Migration name (literal type)
|
|
51
|
-
* @typeParam T - The record's declared state type
|
|
52
|
-
* @typeParam From - The record's type before the step
|
|
53
|
-
* @typeParam To - The record's type after it
|
|
54
|
-
* @param name - Migration name: an identifier, unique on the record, by which
|
|
55
|
-
* a workspace records that it has applied the step
|
|
56
|
-
* @param rec - The record this migration changes
|
|
57
|
-
* @param fn - `(Old) => New`
|
|
58
|
-
* @param config - The step before this one, and the runner
|
|
59
|
-
* @returns A MigrationDef to pass to `e3.package`
|
|
60
|
-
* @throws {Error} When the name is not an identifier, the function is async,
|
|
61
|
-
* calls a platform function or takes other than the one state, or `after`
|
|
62
|
-
* is another record's step or leaves the record as another type than `Old`.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* const RosterV1Type = DictType(StringType, StructType({ name: StringType }));
|
|
67
|
-
* const RosterV2Type = DictType(StringType, StructType({ name: StringType, shift: StringType }));
|
|
68
|
-
* const roster = e3.record('roster', RosterV2Type, new Map());
|
|
69
|
-
*
|
|
70
|
-
* // Every row gains a shift, from the whole state.
|
|
71
|
-
* const addShift = e3.migration.value('add_shift', roster,
|
|
72
|
-
* East.function([RosterV1Type], RosterV2Type, ($, old) =>
|
|
73
|
-
* old.map(($, row) => ({ name: row.name, shift: 'day' }))));
|
|
74
|
-
*
|
|
75
|
-
* const pkg = e3.package('planning', '2.0.0', roster, addShift);
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
declare function value<Name extends string, T extends EastType, From extends EastType, To extends EastType>(name: Name, rec: RecordDef<T>, fn: FunctionExpr<[From], To> | CallableFunctionExpr<[From], To>, config?: MigrationConfig): MigrationDef<Name, T, From, To>;
|
|
79
|
-
/**
|
|
80
|
-
* Defines a migration of a collection record's rows, one at a time: a Dict's
|
|
81
|
-
* rows with its keys unchanged, or an Array's elements in order.
|
|
82
|
-
*
|
|
83
|
-
* The function is `(K, V1) => V2` for a Dict, whose key it may read, or
|
|
84
|
-
* `(T1) => T2` for an Array; its parameters say which. The step runs as a task
|
|
85
|
-
* split over the stored state, so a record of any size migrates a piece at a
|
|
86
|
-
* time, in parallel, each piece cached, and none holds more than its piece.
|
|
87
|
-
*
|
|
88
|
-
* The purity rules and chain checks of {@link value} apply unchanged.
|
|
89
|
-
*
|
|
90
|
-
* @typeParam Name - Migration name (literal type)
|
|
91
|
-
* @typeParam T - The record's declared state type
|
|
92
|
-
* @param name - Migration name: an identifier, unique on the record
|
|
93
|
-
* @param rec - The record this migration changes
|
|
94
|
-
* @param fn - `(T1) => T2` over an Array's elements, or `(K, V1) => V2` over a
|
|
95
|
-
* Dict's rows
|
|
96
|
-
* @param config - The step before this one, and the runner
|
|
97
|
-
* @returns A MigrationDef to pass to `e3.package`
|
|
98
|
-
* @throws {Error} When the name is not an identifier, the function is async,
|
|
99
|
-
* calls a platform function or takes other than one or two parameters, or
|
|
100
|
-
* `after` is another record's step or leaves the record as another type.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* const RowV1Type = StructType({ title: StringType });
|
|
105
|
-
* const RowV2Type = StructType({ title: StringType, owner: StringType });
|
|
106
|
-
* const plans = e3.record('plans', DictType(StringType, RowV2Type), new Map());
|
|
107
|
-
*
|
|
108
|
-
* // Each row gains an owner; the keys are unchanged.
|
|
109
|
-
* const addOwner = e3.migration.rows('add_owner', plans,
|
|
110
|
-
* East.function([StringType, RowV1Type], RowV2Type,
|
|
111
|
-
* ($, id, row) => ({ title: row.title, owner: 'unassigned' })));
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
declare function rows<Name extends string, T extends EastType, E1 extends EastType, E2 extends EastType>(name: Name, rec: RecordDef<T>, fn: FunctionExpr<[E1], E2> | CallableFunctionExpr<[E1], E2>, config?: MigrationConfig): MigrationDef<Name, T, ArrayType<E1>, ArrayType<E2>>;
|
|
115
|
-
declare function rows<Name extends string, T extends EastType, K extends EastType, V1 extends EastType, V2 extends EastType>(name: Name, rec: RecordDef<T>, fn: FunctionExpr<[K, V1], V2> | CallableFunctionExpr<[K, V1], V2>, config?: MigrationConfig): MigrationDef<Name, T, DictType<K, V1>, DictType<K, V2>>;
|
|
116
|
-
/**
|
|
117
|
-
* Defines a migration that re-keys a collection record: a Dict's entries under
|
|
118
|
-
* new keys, or a Set's elements.
|
|
119
|
-
*
|
|
120
|
-
* The function is `(K1, V1) => { key: K2, value: V2 }` for a Dict, or
|
|
121
|
-
* `(T1) => T2` for a Set; its parameters say which. It is the task {@link rows}
|
|
122
|
-
* runs, over each piece of the stored state, and the pieces' outputs are merged
|
|
123
|
-
* by key. Two rows of a Dict landing on one key fail the deploy, naming it,
|
|
124
|
-
* since their values may differ and neither can be chosen; two elements of a
|
|
125
|
-
* Set landing on one are one element, as in any Set, and nothing is lost.
|
|
126
|
-
*
|
|
127
|
-
* The purity rules and chain checks of {@link value} apply unchanged.
|
|
128
|
-
*
|
|
129
|
-
* @typeParam Name - Migration name (literal type)
|
|
130
|
-
* @typeParam T - The record's declared state type
|
|
131
|
-
* @param name - Migration name: an identifier, unique on the record
|
|
132
|
-
* @param rec - The record this migration changes
|
|
133
|
-
* @param fn - `(T1) => T2` over a Set's elements, or
|
|
134
|
-
* `(K1, V1) => { key: K2, value: V2 }` over a Dict's entries
|
|
135
|
-
* @param config - The step before this one, and the runner
|
|
136
|
-
* @returns A MigrationDef to pass to `e3.package`
|
|
137
|
-
* @throws {Error} When the name is not an identifier, the function is async,
|
|
138
|
-
* calls a platform function, takes other than one or two parameters, or over
|
|
139
|
-
* a Dict returns other than `{ key, value }`, when the new key is not a type
|
|
140
|
-
* a key may be, or when `after` is another record's step or leaves the record
|
|
141
|
-
* as another type.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```ts
|
|
145
|
-
* const PlanType = StructType({ site: StringType, title: StringType });
|
|
146
|
-
* const plans = e3.record('plans', DictType(StringType, PlanType), new Map());
|
|
147
|
-
*
|
|
148
|
-
* // Plans were keyed by a number; they are keyed by site and title.
|
|
149
|
-
* const bySite = e3.migration.rekey('by_site', plans,
|
|
150
|
-
* East.function([IntegerType, PlanType], StructType({ key: StringType, value: PlanType }),
|
|
151
|
-
* ($, id, plan) => ({ key: East.str`${plan.site}/${plan.title}`, value: plan })));
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
declare function rekey<Name extends string, T extends EastType, E1 extends EastType, E2 extends EastType>(name: Name, rec: RecordDef<T>, fn: FunctionExpr<[E1], E2> | CallableFunctionExpr<[E1], E2>, config?: MigrationConfig): MigrationDef<Name, T, SetType<E1>, SetType<E2>>;
|
|
155
|
-
declare function rekey<Name extends string, T extends EastType, K1 extends EastType, V1 extends EastType, K2 extends EastType, V2 extends EastType>(name: Name, rec: RecordDef<T>, fn: FunctionExpr<[K1, V1], StructType<{
|
|
156
|
-
key: K2;
|
|
157
|
-
value: V2;
|
|
158
|
-
}>> | CallableFunctionExpr<[K1, V1], StructType<{
|
|
159
|
-
key: K2;
|
|
160
|
-
value: V2;
|
|
161
|
-
}>>, config?: MigrationConfig): MigrationDef<Name, T, DictType<K1, V1>, DictType<K2, V2>>;
|
|
162
|
-
/**
|
|
163
|
-
* The migration forms of a record: {@link value}, {@link rows} and
|
|
164
|
-
* {@link rekey}.
|
|
10
|
+
* Builds a migration step's definition in a form, each guard of the form's
|
|
11
|
+
* applied: its name, its purity, its signature, and its place after the step
|
|
12
|
+
* before it.
|
|
13
|
+
*
|
|
14
|
+
* @param surface - The declaration, as a refusal names it
|
|
15
|
+
* @param form - The step's form
|
|
16
|
+
* @param name - The step
|
|
17
|
+
* @param rec - The record it changes
|
|
18
|
+
* @param fn - Its function
|
|
19
|
+
* @param config - Its runner
|
|
20
|
+
* @param previous - The step before it in the record's list; none for the first
|
|
21
|
+
* @returns The definition
|
|
22
|
+
* @throws {Error} When the name is not an identifier, the runner is not a known
|
|
23
|
+
* runtime, the function is async, calls a platform function or does not fit
|
|
24
|
+
* the form, or the step before it leaves the record as another type than it takes
|
|
165
25
|
*/
|
|
166
|
-
export declare
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
rekey: typeof rekey;
|
|
170
|
-
};
|
|
171
|
-
export {};
|
|
26
|
+
export declare function stepDefinition(surface: string, form: MigrationForm, name: string, rec: RecordDef, fn: IndexFunction, config: {
|
|
27
|
+
runner?: FunctionRunner;
|
|
28
|
+
} | undefined, previous: MigrationDef | undefined): MigrationDef;
|
|
172
29
|
//# sourceMappingURL=migration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../src/migration.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../src/migration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAkD,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAmC,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AA0GnF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,aAAa,EACrF,MAAM,EAAE;IAAE,MAAM,CAAC,EAAE,cAAc,CAAA;CAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,YAAY,GAAG,SAAS,GAClF,YAAY,CAEd"}
|