@voidhash/mimic 1.0.0-beta.16 → 1.0.0-beta.17

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 (95) hide show
  1. package/dist/EffectSchema.cjs +3 -3
  2. package/dist/EffectSchema.d.cts +5 -5
  3. package/dist/EffectSchema.d.cts.map +1 -1
  4. package/dist/EffectSchema.d.mts +5 -5
  5. package/dist/EffectSchema.d.mts.map +1 -1
  6. package/dist/EffectSchema.mjs +3 -3
  7. package/dist/EffectSchema.mjs.map +1 -1
  8. package/dist/FractionalIndex.mjs.map +1 -1
  9. package/dist/Operation.d.cts +4 -4
  10. package/dist/Operation.d.cts.map +1 -1
  11. package/dist/Operation.d.mts +4 -4
  12. package/dist/Operation.d.mts.map +1 -1
  13. package/dist/Operation.mjs.map +1 -1
  14. package/dist/OperationDefinition.d.cts +2 -2
  15. package/dist/OperationDefinition.d.cts.map +1 -1
  16. package/dist/OperationDefinition.d.mts +2 -2
  17. package/dist/OperationDefinition.d.mts.map +1 -1
  18. package/dist/OperationDefinition.mjs.map +1 -1
  19. package/dist/Presence.mjs.map +1 -1
  20. package/dist/SchemaJSON.cjs +305 -0
  21. package/dist/SchemaJSON.d.cts +11 -0
  22. package/dist/SchemaJSON.d.cts.map +1 -0
  23. package/dist/SchemaJSON.d.mts +11 -0
  24. package/dist/SchemaJSON.d.mts.map +1 -0
  25. package/dist/SchemaJSON.mjs +301 -0
  26. package/dist/SchemaJSON.mjs.map +1 -0
  27. package/dist/index.cjs +7 -0
  28. package/dist/index.d.cts +2 -1
  29. package/dist/index.d.mts +2 -1
  30. package/dist/index.mjs +2 -1
  31. package/dist/primitives/Array.cjs +12 -2
  32. package/dist/primitives/Array.d.cts.map +1 -1
  33. package/dist/primitives/Array.d.mts.map +1 -1
  34. package/dist/primitives/Array.mjs +12 -2
  35. package/dist/primitives/Array.mjs.map +1 -1
  36. package/dist/primitives/Boolean.mjs.map +1 -1
  37. package/dist/primitives/Either.mjs.map +1 -1
  38. package/dist/primitives/Literal.mjs.map +1 -1
  39. package/dist/primitives/Number.cjs +27 -5
  40. package/dist/primitives/Number.d.cts.map +1 -1
  41. package/dist/primitives/Number.d.mts.map +1 -1
  42. package/dist/primitives/Number.mjs +27 -5
  43. package/dist/primitives/Number.mjs.map +1 -1
  44. package/dist/primitives/String.cjs +44 -13
  45. package/dist/primitives/String.d.cts.map +1 -1
  46. package/dist/primitives/String.d.mts.map +1 -1
  47. package/dist/primitives/String.mjs +44 -13
  48. package/dist/primitives/String.mjs.map +1 -1
  49. package/dist/primitives/Union.mjs.map +1 -1
  50. package/dist/primitives/shared.d.cts +2 -0
  51. package/dist/primitives/shared.d.cts.map +1 -1
  52. package/dist/primitives/shared.d.mts +2 -0
  53. package/dist/primitives/shared.d.mts.map +1 -1
  54. package/dist/primitives/shared.mjs.map +1 -1
  55. package/package.json +15 -8
  56. package/src/EffectSchema.ts +3 -3
  57. package/src/FractionalIndex.ts +18 -18
  58. package/src/Operation.ts +5 -5
  59. package/src/OperationDefinition.ts +2 -2
  60. package/src/Presence.ts +3 -3
  61. package/src/SchemaJSON.ts +396 -0
  62. package/src/index.ts +1 -0
  63. package/src/primitives/Array.ts +18 -8
  64. package/src/primitives/Boolean.ts +2 -2
  65. package/src/primitives/Either.ts +2 -2
  66. package/src/primitives/Literal.ts +2 -2
  67. package/src/primitives/Number.ts +44 -22
  68. package/src/primitives/String.ts +61 -34
  69. package/src/primitives/Union.ts +1 -1
  70. package/src/primitives/shared.ts +2 -0
  71. package/.turbo/turbo-build.log +0 -270
  72. package/tests/Document.test.ts +0 -557
  73. package/tests/EffectSchema.test.ts +0 -546
  74. package/tests/FractionalIndex.test.ts +0 -377
  75. package/tests/OperationPath.test.ts +0 -151
  76. package/tests/Presence.test.ts +0 -321
  77. package/tests/Primitive.test.ts +0 -381
  78. package/tests/client/ClientDocument.test.ts +0 -1981
  79. package/tests/client/WebSocketTransport.test.ts +0 -1217
  80. package/tests/primitives/Array.test.ts +0 -526
  81. package/tests/primitives/Boolean.test.ts +0 -126
  82. package/tests/primitives/Either.test.ts +0 -707
  83. package/tests/primitives/Lazy.test.ts +0 -143
  84. package/tests/primitives/Literal.test.ts +0 -122
  85. package/tests/primitives/Number.test.ts +0 -133
  86. package/tests/primitives/String.test.ts +0 -128
  87. package/tests/primitives/Struct.test.ts +0 -1154
  88. package/tests/primitives/Tree.test.ts +0 -1139
  89. package/tests/primitives/TreeNode.test.ts +0 -50
  90. package/tests/primitives/Union.test.ts +0 -554
  91. package/tests/server/ServerDocument.test.ts +0 -903
  92. package/tsconfig.build.json +0 -24
  93. package/tsconfig.json +0 -8
  94. package/tsdown.config.ts +0 -18
  95. package/vitest.mts +0 -11
package/package.json CHANGED
@@ -1,45 +1,52 @@
1
1
  {
2
2
  "name": "@voidhash/mimic",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/voidhashcom/voidhash",
8
8
  "directory": "packages/mimic"
9
9
  },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "src"
16
+ ],
10
17
  "main": "./src/index.ts",
11
18
  "exports": {
12
19
  ".": {
20
+ "types": "./src/index.ts",
13
21
  "import": "./dist/index.mjs",
14
- "types": "./dist/index.d.mts",
15
22
  "require": "./dist/index.cjs"
16
23
  },
17
24
  "./server": {
25
+ "types": "./src/server/index.ts",
18
26
  "import": "./dist/server/index.mjs",
19
- "types": "./dist/server/index.d.mts",
20
27
  "require": "./dist/server/index.cjs"
21
28
  },
22
29
  "./client": {
30
+ "types": "./src/client/index.ts",
23
31
  "import": "./dist/client/index.mjs",
24
- "types": "./dist/client/index.d.mts",
25
32
  "require": "./dist/client/index.cjs"
26
33
  }
27
34
  },
28
35
  "devDependencies": {
29
- "@effect/vitest": "^0.27.0",
36
+ "@effect/vitest": "4.0.0-beta.21",
30
37
  "tsdown": "^0.18.2",
31
38
  "typescript": "5.8.3",
32
39
  "vite-tsconfig-paths": "^5.1.4",
33
40
  "vitest": "^3.2.4",
34
- "@voidhash/tsconfig": "1.0.0-beta.16"
41
+ "@voidhash/tsconfig": "1.0.0-beta.17"
35
42
  },
36
43
  "peerDependencies": {
37
- "effect": "^3.19.12"
44
+ "effect": "4.0.0-beta.21"
38
45
  },
39
46
  "scripts": {
40
47
  "build": "tsdown",
41
48
  "lint": "biome check .",
42
- "typecheck": "tsc --noEmit",
49
+ "typecheck": "tsgo --noEmit",
43
50
  "test": "vitest run -c vitest.mts"
44
51
  }
45
52
  }
@@ -229,7 +229,7 @@ function buildUnionSetSchema(unionPrimitive: UnionPrimitive<UnionVariants, any,
229
229
  return variantSchemas[0]!;
230
230
  }
231
231
 
232
- return Schema.Union(...variantSchemas as [Schema.Schema<any>, Schema.Schema<any>, ...Schema.Schema<any>[]]);
232
+ return Schema.Union(variantSchemas as any);
233
233
  }
234
234
 
235
235
  /**
@@ -252,7 +252,7 @@ function buildEitherSchema(eitherPrimitive: EitherPrimitive<readonly ScalarPrimi
252
252
  return variantSchemas[0]!;
253
253
  }
254
254
 
255
- return Schema.Union(...variantSchemas as [Schema.Schema<any>, Schema.Schema<any>, ...Schema.Schema<any>[]]);
255
+ return Schema.Union(variantSchemas as any);
256
256
  }
257
257
 
258
258
  /**
@@ -276,7 +276,7 @@ function buildUnionUpdateSchema(unionPrimitive: UnionPrimitive<UnionVariants, an
276
276
  return variantSchemas[0]!;
277
277
  }
278
278
 
279
- return Schema.Union(...variantSchemas as [Schema.Schema<any>, Schema.Schema<any>, ...Schema.Schema<any>[]]);
279
+ return Schema.Union(variantSchemas as any);
280
280
  }
281
281
 
282
282
  /**
@@ -729,7 +729,7 @@ export function decrementInteger(
729
729
  export function jitterString(
730
730
  orderKey: string,
731
731
  charSet: IndexedCharacterSet
732
- ): Effect.Effect<string, Error, Random.Random> {
732
+ ): Effect.Effect<string, Error, typeof Random.Random> {
733
733
  return Effect.gen(function* () {
734
734
  const randomValue = yield* Random.next
735
735
  const shift = yield* encodeToCharSet(
@@ -744,7 +744,7 @@ export function padAndJitterString(
744
744
  orderKey: string,
745
745
  numberOfChars: number,
746
746
  charSet: IndexedCharacterSet
747
- ): Effect.Effect<string, Error, Random.Random> {
747
+ ): Effect.Effect<string, Error, typeof Random.Random> {
748
748
  return Effect.gen(function* () {
749
749
  const paddedKey = orderKey.padEnd(
750
750
  orderKey.length + numberOfChars,
@@ -920,7 +920,7 @@ export function generateJitteredKeyBetween(
920
920
  lower: string | null,
921
921
  upper: string | null,
922
922
  charSet: IndexedCharacterSet = base62CharSet()
923
- ): Effect.Effect<string, Error, Random.Random> {
923
+ ): Effect.Effect<string, Error, typeof Random.Random> {
924
924
  return Effect.gen(function* () {
925
925
  const key = yield* generateKeyBetween(lower, upper, charSet)
926
926
  const paddingNeeded = yield* paddingNeededForJitter(key, upper, charSet)
@@ -940,7 +940,7 @@ export function generateNJitteredKeysBetween(
940
940
  upper: string | null,
941
941
  n: number,
942
942
  charSet: IndexedCharacterSet = base62CharSet()
943
- ): Effect.Effect<string[], Error, Random.Random> {
943
+ ): Effect.Effect<string[], Error, typeof Random.Random> {
944
944
  return Effect.gen(function* () {
945
945
  if (n === 0) {
946
946
  return []
@@ -1007,12 +1007,12 @@ export class IndexGenerator {
1007
1007
  * Generate any number of keys at the start of the list (before the first key).
1008
1008
  * Optionally you can supply a groupId to generate keys at the start of a specific group.
1009
1009
  */
1010
- public nKeysStart(n: number, groupId?: string): Effect.Effect<string[], Error, Random.Random> {
1010
+ public nKeysStart(n: number, groupId?: string): Effect.Effect<string[], Error, typeof Random.Random> {
1011
1011
  const self = this
1012
1012
  return Effect.gen(function* () {
1013
- yield* Effect.try(() => {
1013
+ yield* Effect.try({ try: () => {
1014
1014
  self.validateGroupId(groupId)
1015
- })
1015
+ }, catch: (e) => e instanceof Error ? e : new Error(String(e)) })
1016
1016
  const firstKey = self.firstOfGroup(groupId)
1017
1017
  return yield* self.generateNKeysBetween(null, firstKey, n, groupId)
1018
1018
  })
@@ -1022,7 +1022,7 @@ export class IndexGenerator {
1022
1022
  * Generate a single key at the start of the list (before the first key).
1023
1023
  * Optionally you can supply a groupId to generate a key at the start of a specific group.
1024
1024
  */
1025
- public keyStart(groupId?: string): Effect.Effect<string, Error, Random.Random> {
1025
+ public keyStart(groupId?: string): Effect.Effect<string, Error, typeof Random.Random> {
1026
1026
  const self = this
1027
1027
  return Effect.gen(function* () {
1028
1028
  const keys = yield* self.nKeysStart(1, groupId)
@@ -1034,12 +1034,12 @@ export class IndexGenerator {
1034
1034
  * Generate any number of keys at the end of the list (after the last key).
1035
1035
  * Optionally you can supply a groupId to generate keys at the end of a specific group.
1036
1036
  */
1037
- public nKeysEnd(n: number, groupId?: string): Effect.Effect<string[], Error, Random.Random> {
1037
+ public nKeysEnd(n: number, groupId?: string): Effect.Effect<string[], Error, typeof Random.Random> {
1038
1038
  const self = this
1039
1039
  return Effect.gen(function* () {
1040
- yield* Effect.try(() => {
1040
+ yield* Effect.try({ try: () => {
1041
1041
  self.validateGroupId(groupId)
1042
- })
1042
+ }, catch: (e) => e instanceof Error ? e : new Error(String(e)) })
1043
1043
  const lastKey = self.lastOfGroup(groupId)
1044
1044
  return yield* self.generateNKeysBetween(lastKey, null, n, groupId)
1045
1045
  })
@@ -1049,7 +1049,7 @@ export class IndexGenerator {
1049
1049
  * Generate a single key at the end of the list (after the last key).
1050
1050
  * Optionally you can supply a groupId to generate a key at the end of a specific group.
1051
1051
  */
1052
- public keyEnd(groupId?: string): Effect.Effect<string, Error, Random.Random> {
1052
+ public keyEnd(groupId?: string): Effect.Effect<string, Error, typeof Random.Random> {
1053
1053
  const self = this
1054
1054
  return Effect.gen(function* () {
1055
1055
  const keys = yield* self.nKeysEnd(1, groupId)
@@ -1061,7 +1061,7 @@ export class IndexGenerator {
1061
1061
  * Generate any number of keys behind a specific key and in front of the next key.
1062
1062
  * GroupId will be inferred from the orderKey if working with groups
1063
1063
  */
1064
- public nKeysAfter(orderKey: string, n: number): Effect.Effect<string[], Error, Random.Random> {
1064
+ public nKeysAfter(orderKey: string, n: number): Effect.Effect<string[], Error, typeof Random.Random> {
1065
1065
  const self = this
1066
1066
  return Effect.gen(function* () {
1067
1067
  const keyAfter = yield* self.getKeyAfter(orderKey)
@@ -1073,7 +1073,7 @@ export class IndexGenerator {
1073
1073
  * Generate a single key behind a specific key and in front of the next key.
1074
1074
  * GroupId will be inferred from the orderKey if working with groups
1075
1075
  */
1076
- public keyAfter(orderKey: string): Effect.Effect<string, Error, Random.Random> {
1076
+ public keyAfter(orderKey: string): Effect.Effect<string, Error, typeof Random.Random> {
1077
1077
  const self = this
1078
1078
  return Effect.gen(function* () {
1079
1079
  const keys = yield* self.nKeysAfter(orderKey, 1)
@@ -1085,7 +1085,7 @@ export class IndexGenerator {
1085
1085
  * Generate any number of keys in front of a specific key and behind the previous key.
1086
1086
  * GroupId will be inferred from the orderKey if working with groups
1087
1087
  */
1088
- public nKeysBefore(orderKey: string, n: number): Effect.Effect<string[], Error, Random.Random> {
1088
+ public nKeysBefore(orderKey: string, n: number): Effect.Effect<string[], Error, typeof Random.Random> {
1089
1089
  const self = this
1090
1090
  return Effect.gen(function* () {
1091
1091
  const keyBefore = yield* self.getKeyBefore(orderKey)
@@ -1097,7 +1097,7 @@ export class IndexGenerator {
1097
1097
  * Generate a single key in front of a specific key and behind the previous key.
1098
1098
  * GroupId will be inferred from the orderKey if working with groups
1099
1099
  */
1100
- public keyBefore(orderKey: string): Effect.Effect<string, Error, Random.Random> {
1100
+ public keyBefore(orderKey: string): Effect.Effect<string, Error, typeof Random.Random> {
1101
1101
  const self = this
1102
1102
  return Effect.gen(function* () {
1103
1103
  const keys = yield* self.nKeysBefore(orderKey, 1)
@@ -1113,7 +1113,7 @@ export class IndexGenerator {
1113
1113
  upperKey: string | null,
1114
1114
  n: number,
1115
1115
  groupId: string | undefined
1116
- ): Effect.Effect<string[], Error, Random.Random> {
1116
+ ): Effect.Effect<string[], Error, typeof Random.Random> {
1117
1117
  const self = this
1118
1118
  const lower = self.groupLessKey(lowerKey)
1119
1119
  const upper = self.groupLessKey(upperKey)
@@ -1128,7 +1128,7 @@ export class IndexGenerator {
1128
1128
  return Effect.gen(function* () {
1129
1129
  const keys = yield* generateNKeysBetween(lower, upper, n, self.charSet)
1130
1130
  return !groupId ? keys : keys.map((key) => groupId + key)
1131
- }).pipe(Effect.provideService(Random as any, Random.make(Math.random())))
1131
+ }).pipe(Random.withSeed(Math.random()))
1132
1132
  }
1133
1133
  }
1134
1134
 
package/src/Operation.ts CHANGED
@@ -4,7 +4,7 @@ import * as OperationDefinition from "./OperationDefinition"
4
4
  import { Schema } from "effect";
5
5
 
6
6
 
7
- export type Operation<TKind, TPayload extends Schema.Schema.Any, TDef extends OperationDefinition.OperationDefinition<TKind, TPayload, any>> = {
7
+ export type Operation<TKind, TPayload extends Schema.Top, TDef extends OperationDefinition.OperationDefinition<TKind, TPayload, any>> = {
8
8
  readonly kind: TKind
9
9
  readonly path: OperationPath.OperationPath
10
10
  readonly payload: Schema.Schema.Type<TPayload>,
@@ -12,7 +12,7 @@ export type Operation<TKind, TPayload extends Schema.Schema.Any, TDef extends Op
12
12
 
13
13
  } & TDef
14
14
 
15
- export const fromDefinition = <TKind, TPayload extends Schema.Schema.Any, TDef extends OperationDefinition.OperationDefinition<TKind, TPayload, any>>(operationPath: OperationPath.OperationPath, definition: TDef, payload: Schema.Schema.Type<TPayload>): Operation<TKind, TPayload, TDef> => {
15
+ export const fromDefinition = <TKind, TPayload extends Schema.Top, TDef extends OperationDefinition.OperationDefinition<TKind, TPayload, any>>(operationPath: OperationPath.OperationPath, definition: TDef, payload: Schema.Schema.Type<TPayload>): Operation<TKind, TPayload, TDef> => {
16
16
  return {
17
17
  kind: definition.kind,
18
18
  path: operationPath,
@@ -35,7 +35,7 @@ export interface EncodedOperation {
35
35
  * @param operation - The operation to encode.
36
36
  * @returns The encoded representation.
37
37
  */
38
- export const encode = <TKind, TPayload extends Schema.Schema.Any, TDef extends OperationDefinition.OperationDefinition<TKind, TPayload, any>>(
38
+ export const encode = <TKind, TPayload extends Schema.Top, TDef extends OperationDefinition.OperationDefinition<TKind, TPayload, any>>(
39
39
  operation: Operation<TKind, TPayload, TDef>
40
40
  ): EncodedOperation => {
41
41
  return {
@@ -52,10 +52,10 @@ export const encode = <TKind, TPayload extends Schema.Schema.Any, TDef extends O
52
52
  * @param encoded - The encoded representation.
53
53
  * @returns The decoded Operation (without definition-specific methods).
54
54
  */
55
- export const decode = (encoded: EncodedOperation): Operation<unknown, Schema.Schema.Any, any> => {
55
+ export const decode = (encoded: EncodedOperation): Operation<unknown, Schema.Top, any> => {
56
56
  return {
57
57
  kind: encoded.kind,
58
58
  path: OperationPath.decode(encoded.path),
59
59
  payload: encoded.payload,
60
- } as Operation<unknown, Schema.Schema.Any, any>
60
+ } as Operation<unknown, Schema.Top, any>
61
61
  }
@@ -2,14 +2,14 @@ import { Schema } from "effect";
2
2
 
3
3
  type Mutable<T> = T extends ReadonlyArray<infer U> ? Array<U> : { -readonly [K in keyof T]: T[K] };
4
4
 
5
- export interface OperationDefinition<TKind, TPayload extends Schema.Schema.Any, TTarget extends Schema.Schema.Any> {
5
+ export interface OperationDefinition<TKind, TPayload extends Schema.Top, TTarget extends Schema.Top> {
6
6
  readonly kind: TKind
7
7
  readonly payload: TPayload
8
8
  readonly target: TTarget
9
9
  readonly deduplicable?: boolean
10
10
  }
11
11
 
12
- export const make = <TKind, TPayload extends Schema.Schema.Any, TTarget extends Schema.Schema.Any>(options: {
12
+ export const make = <TKind, TPayload extends Schema.Top, TTarget extends Schema.Top>(options: {
13
13
  readonly kind: TKind
14
14
  readonly payload: TPayload
15
15
  readonly target: TTarget
package/src/Presence.ts CHANGED
@@ -99,7 +99,7 @@ export const validate = <TData,>(
99
99
  presence: Presence<TData>,
100
100
  data: unknown
101
101
  ): TData => {
102
- return Schema.decodeUnknownSync(presence.schema)(data);
102
+ return Schema.decodeUnknownSync(presence.schema as any)(data);
103
103
  };
104
104
 
105
105
  /**
@@ -115,7 +115,7 @@ export const validateSafe = <TData,>(
115
115
  data: unknown
116
116
  ): TData | undefined => {
117
117
  try {
118
- return Schema.decodeUnknownSync(presence.schema)(data);
118
+ return Schema.decodeUnknownSync(presence.schema as any)(data);
119
119
  } catch {
120
120
  return undefined;
121
121
  }
@@ -133,7 +133,7 @@ export const isValid = <TData,>(
133
133
  data: unknown
134
134
  ): data is TData => {
135
135
  try {
136
- Schema.decodeUnknownSync(presence.schema)(data);
136
+ Schema.decodeUnknownSync(presence.schema as any)(data);
137
137
  return true;
138
138
  } catch {
139
139
  return false;