@dxos/keys 0.8.4-main.fd6878d → 0.8.4-main.fffef41

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.
@@ -1,10 +1,37 @@
1
- import { Schema } from 'effect';
1
+ import * as Schema from 'effect/Schema';
2
2
  declare const ObjectIdSchema: Schema.refine<string, typeof Schema.String>;
3
3
  export type ObjectId = typeof ObjectIdSchema.Type;
4
4
  export interface ObjectIdClass extends Schema.SchemaClass<ObjectId, string> {
5
+ /**
6
+ * @returns true if the string is a valid ObjectId.
7
+ */
5
8
  isValid(id: string): id is ObjectId;
9
+ /**
10
+ * Creates an ObjectId from a string validating the format.
11
+ */
6
12
  make(id: string): ObjectId;
13
+ /**
14
+ * Generates a random ObjectId.
15
+ */
7
16
  random(): ObjectId;
17
+ /**
18
+ * WARNING: To be used only within tests.
19
+ *
20
+ * Disables randomness in ObjectId generation, causing the same sequence of IDs to be generated.
21
+ * Do not use in production code as this will cause data collisions.
22
+ * Place this at the top of the test file to ensure that the same sequence of IDs is generated.
23
+ *
24
+ * ```ts
25
+ * ObjectId.dangerouslyDisableRandomness();
26
+ *
27
+ * describe('suite', () => {
28
+ * // ...
29
+ * });
30
+ * ```
31
+ *
32
+ * NOTE: The generated IDs depend on the order of ObjectId.random() calls, which might be affected by test order, scheduling, etc.
33
+ */
34
+ dangerouslyDisableRandomness(): void;
8
35
  }
9
36
  /**
10
37
  * Randomly generated unique identifier for an object.
@@ -12,5 +39,27 @@ export interface ObjectIdClass extends Schema.SchemaClass<ObjectId, string> {
12
39
  * Follows ULID spec.
13
40
  */
14
41
  export declare const ObjectId: ObjectIdClass;
42
+ /**
43
+ * Simple Linear Congruential Generator (LCG) for pseudo-random number generation.
44
+ * Returns numbers in the range [0, 1) (0 inclusive, 1 exclusive).
45
+ */
46
+ export declare class SimplePRNG {
47
+ #private;
48
+ /**
49
+ * Creates a new PRNG instance.
50
+ * @param seed - Initial seed value. If not provided, uses 0.
51
+ */
52
+ constructor(seed?: number);
53
+ /**
54
+ * Generates the next pseudo-random number in the range [0, 1).
55
+ * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
56
+ */
57
+ next(): number;
58
+ /**
59
+ * Resets the generator with a new seed.
60
+ * @param seed - New seed value.
61
+ */
62
+ reset(seed: number): void;
63
+ }
15
64
  export {};
16
65
  //# sourceMappingURL=object-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"object-id.d.ts","sourceRoot":"","sources":["../../../src/object-id.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,QAAA,MAAM,cAAc,6CAGlB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC;AAElD,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC;IACzE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,QAAQ,CAAC;IACpC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC3B,MAAM,IAAI,QAAQ,CAAC;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,aAatB,CAAC"}
1
+ {"version":3,"file":"object-id.d.ts","sourceRoot":"","sources":["../../../src/object-id.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAMxC,QAAA,MAAM,cAAc,6CAGlB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC;AAElD,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC;IACzE;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,QAAQ,CAAC;IAEpC;;OAEG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC;IAE3B;;OAEG;IACH,MAAM,IAAI,QAAQ,CAAC;IAEnB;;;;;;;;;;;;;;;;OAgBG;IACH,4BAA4B,IAAI,IAAI,CAAC;CACtC;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,aAqBtB,CAAC;AAYF;;;GAGG;AACH,qBAAa,UAAU;;IAQrB;;;OAGG;gBACS,IAAI,GAAE,MAAU;IAI5B;;;OAGG;IACH,IAAI,IAAI,MAAM;IAQd;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAG1B"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Simple Linear Congruential Generator (LCG) for pseudo-random number generation.
3
+ * Returns numbers in the range [0, 1) (0 inclusive, 1 exclusive).
4
+ */
5
+ export declare class SimplePRNG {
6
+ private _seed;
7
+ private static readonly _a;
8
+ private static readonly _c;
9
+ private static readonly _m;
10
+ /**
11
+ * Creates a new PRNG instance.
12
+ * @param seed - Initial seed value. If not provided, uses current timestamp.
13
+ */
14
+ constructor(seed?: number);
15
+ /**
16
+ * Generates the next pseudo-random number in the range [0, 1).
17
+ * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
18
+ */
19
+ next(): number;
20
+ /**
21
+ * Resets the generator with a new seed.
22
+ * @param seed - New seed value.
23
+ */
24
+ reset(seed: number): void;
25
+ }
26
+ /**
27
+ * Creates a simple PRNG function with optional seed.
28
+ * @param seed - Optional seed value.
29
+ * @returns A function that returns pseudo-random numbers in [0, 1).
30
+ */
31
+ export declare const createPRNG: (seed?: number) => (() => number);
32
+ //# sourceMappingURL=prng.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prng.d.ts","sourceRoot":"","sources":["../../../src/prng.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAS;IAGtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAW;IACrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAc;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAmB;IAE7C;;;OAGG;gBACS,IAAI,CAAC,EAAE,MAAM;IAIzB;;;OAGG;IACH,IAAI,IAAI,MAAM;IAQd;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAG1B;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,CAAC,MAAM,MAAM,CAGvD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Schema } from 'effect';
1
+ import * as Schema from 'effect/Schema';
2
2
  /**
3
3
  * A unique identifier for a space.
4
4
  * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).
@@ -1 +1 @@
1
- {"version":3,"file":"space-id.d.ts","sourceRoot":"","sources":["../../../src/space-id.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAiBhC;;;;GAIG;AAEH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAEnD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC;IACvC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,UAAU,CAAC;IACvC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,OAAO,CAAC;IAC7C,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACjC,MAAM,EAAE,MAAM,OAAO,CAAC;CAoBvB,CAAC"}
1
+ {"version":3,"file":"space-id.d.ts","sourceRoot":"","sources":["../../../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