@wavehouse/chtypes 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/setup.js CHANGED
@@ -11,12 +11,16 @@
11
11
  * the first open records the empty setup: the empty zone, which the
12
12
  * library reads as UTC, and no defaults. Once an image completes loader
13
13
  * step 7 (`chs_initialize`, then `chs_set_defaults` when there are
14
- * defaults), `setup` succeeds only with exactly the setup in effect. If
15
- * step 7 fails before any image has completed it, the record is cleared,
16
- * so a corrected `setup` is accepted and the next open runs step 7 with it.
14
+ * defaults), `setup` succeeds only with exactly the setup in effect
15
+ * (`latchSetup`). Until then, an open that attempted a load and failed,
16
+ * whatever failed (the fetch, the signature, an incompatible artifact, a
17
+ * missing symbol or step 7), keeps the record but makes it replaceable
18
+ * (`settleFailedOpen`): a retry with no new `setup` runs under the
19
+ * recorded setup, and a different `setup` replaces it. A refused version
20
+ * spelling or an unverified open without the caller's opt-in fails before
21
+ * any load is attempted, and unlocks nothing.
17
22
  * 3. Every image is set up at loader step 7, once, from this record
18
- * (`./abi1/loader.ts`), which reports how step 7 ended to `settleSetup`;
19
- * nothing sets either again for that image.
23
+ * (`./abi1/loader.ts`); nothing sets either again for that image.
20
24
  *
21
25
  * This is state of the isolate: every worker thread calls it identically, and
22
26
  * a worker whose zone differs is refused by the library at its first open.
@@ -26,6 +30,10 @@ import { validateDefaults } from './settings.js';
26
30
  let recorded;
27
31
  /** Whether any image has completed loader step 7 under the record. */
28
32
  let latched = false;
33
+ /** Whether an open that attempted a load failed since the record was last set or committed, with nothing latched: a different `setup` then replaces the record instead of being refused. */
34
+ let replaceable = false;
35
+ /** Counts the records `setup` made or replaced. An open reads it when its attempt begins, and unlocks the record on failure only if it is unchanged: a failed open never unlocks a setup recorded after it began. */
36
+ let generation = 0;
29
37
  function describe(s) {
30
38
  const keys = Object.keys(s.defaults).sort();
31
39
  const defaults = keys.length === 0 ? 'no defaults' : `defaults ${JSON.stringify(Object.fromEntries(keys.map((k) => [k, s.defaults[k]])))}`;
@@ -46,34 +54,43 @@ export function setup(options = {}) {
46
54
  const defaults = options.defaults ?? {};
47
55
  validateDefaults(defaults);
48
56
  const next = { timezone, defaults: { ...defaults } };
49
- if (recorded === undefined) {
50
- recorded = next;
57
+ if (recorded !== undefined && same(recorded, next))
51
58
  return;
52
- }
53
- if (!same(recorded, next)) {
59
+ if (recorded !== undefined && (latched || !replaceable)) {
54
60
  throw usageError(`setup was already fixed at ${describe(recorded)}; it was asked for ${describe(next)}. The first setup stands: call setup before the first open, once.`);
55
61
  }
62
+ // A first record, or a replacement after a failed open: either way the new record is locked until the next failed open.
63
+ recorded = next;
64
+ replaceable = false;
65
+ generation += 1;
56
66
  }
57
- /** The setup in effect, recording the empty setup if none was recorded: what an open does before step 7. */
67
+ /** The setup in effect, recording the empty setup if none was recorded: what an open does before step 7. The load that follows claims the record, so it is locked again. */
58
68
  export function commitSetup() {
59
69
  recorded ??= { timezone: '', defaults: {} };
70
+ replaceable = false;
60
71
  return recorded;
61
72
  }
73
+ /** Read when an open's attempt begins, for `settleFailedOpen`. */
74
+ export function setupGeneration() {
75
+ return generation;
76
+ }
77
+ /** An image completed loader step 7: from then on the setup in effect stands. An open calls it synchronously after the load that committed the record, so it latches the record that load ran under. */
78
+ export function latchSetup() {
79
+ latched = true;
80
+ replaceable = false;
81
+ }
62
82
  /**
63
- * How loader step 7 ended, reported by the loader. A success latches the setup in effect. A failure before any image has completed step 7 clears the record, so `setup` accepts a corrected setup; once the setup has latched, a failure changes nothing (the library's own process-once rule answers a different zone on an image that already has one).
64
- * An isolate runs this synchronously with the commit and the load that preceded it, so the record it settles is the one that load ran under.
83
+ * Settle an open that attempted a load and failed, whatever failed. While no image has completed step 7 it unlocks the record: the record stays, so a retry runs under it, and a different `setup` may replace it. It leaves alone a setup recorded or replaced after the open began (`began` is `setupGeneration()` then), and once the setup has latched it changes nothing: the library's own process-once rule answers a different zone on an image that already has one.
65
84
  */
66
- export function settleSetup(completed) {
67
- if (completed) {
68
- latched = true;
85
+ export function settleFailedOpen(began) {
86
+ if (latched || recorded === undefined || generation !== began)
69
87
  return;
70
- }
71
- if (!latched)
72
- recorded = undefined;
88
+ replaceable = true;
73
89
  }
74
- /** Test only: forget the recorded setup and the latch. Not part of the public API. */
90
+ /** Test only: forget the recorded setup, the latch and the unlock. Not part of the public API. */
75
91
  export function resetSetupForTests() {
76
92
  recorded = undefined;
77
93
  latched = false;
94
+ replaceable = false;
78
95
  }
79
96
  //# sourceMappingURL=setup.js.map
package/dist/setup.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAiB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAchE,IAAI,QAAkC,CAAC;AACvC,sEAAsE;AACtE,IAAI,OAAO,GAAG,KAAK,CAAC;AAEpB,SAAS,QAAQ,CAAC,CAAe;IAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3I,OAAO,QAAQ,CAAC,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,QAA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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavehouse/chtypes",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "ClickHouse's own type system, per version, over the frozen chs_* C ABI",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",