@voidhash/mimic 1.0.0-beta.15 → 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 (112) hide show
  1. package/dist/Document.cjs +0 -3
  2. package/dist/Document.d.mts.map +1 -1
  3. package/dist/Document.mjs +0 -3
  4. package/dist/Document.mjs.map +1 -1
  5. package/dist/EffectSchema.cjs +3 -3
  6. package/dist/EffectSchema.d.cts +5 -5
  7. package/dist/EffectSchema.d.cts.map +1 -1
  8. package/dist/EffectSchema.d.mts +5 -5
  9. package/dist/EffectSchema.d.mts.map +1 -1
  10. package/dist/EffectSchema.mjs +3 -3
  11. package/dist/EffectSchema.mjs.map +1 -1
  12. package/dist/FractionalIndex.mjs.map +1 -1
  13. package/dist/Operation.d.cts +4 -4
  14. package/dist/Operation.d.cts.map +1 -1
  15. package/dist/Operation.d.mts +4 -4
  16. package/dist/Operation.d.mts.map +1 -1
  17. package/dist/Operation.mjs.map +1 -1
  18. package/dist/OperationDefinition.d.cts +2 -2
  19. package/dist/OperationDefinition.d.cts.map +1 -1
  20. package/dist/OperationDefinition.d.mts +2 -2
  21. package/dist/OperationDefinition.d.mts.map +1 -1
  22. package/dist/OperationDefinition.mjs.map +1 -1
  23. package/dist/Presence.mjs.map +1 -1
  24. package/dist/Primitive.d.cts +2 -2
  25. package/dist/Primitive.d.mts +2 -2
  26. package/dist/SchemaJSON.cjs +305 -0
  27. package/dist/SchemaJSON.d.cts +11 -0
  28. package/dist/SchemaJSON.d.cts.map +1 -0
  29. package/dist/SchemaJSON.d.mts +11 -0
  30. package/dist/SchemaJSON.d.mts.map +1 -0
  31. package/dist/SchemaJSON.mjs +301 -0
  32. package/dist/SchemaJSON.mjs.map +1 -0
  33. package/dist/index.cjs +7 -0
  34. package/dist/index.d.cts +2 -1
  35. package/dist/index.d.mts +2 -1
  36. package/dist/index.mjs +2 -1
  37. package/dist/primitives/Array.cjs +12 -2
  38. package/dist/primitives/Array.d.cts.map +1 -1
  39. package/dist/primitives/Array.d.mts.map +1 -1
  40. package/dist/primitives/Array.mjs +12 -2
  41. package/dist/primitives/Array.mjs.map +1 -1
  42. package/dist/primitives/Boolean.mjs.map +1 -1
  43. package/dist/primitives/Either.mjs.map +1 -1
  44. package/dist/primitives/Literal.mjs.map +1 -1
  45. package/dist/primitives/Number.cjs +27 -5
  46. package/dist/primitives/Number.d.cts.map +1 -1
  47. package/dist/primitives/Number.d.mts.map +1 -1
  48. package/dist/primitives/Number.mjs +27 -5
  49. package/dist/primitives/Number.mjs.map +1 -1
  50. package/dist/primitives/String.cjs +44 -13
  51. package/dist/primitives/String.d.cts.map +1 -1
  52. package/dist/primitives/String.d.mts.map +1 -1
  53. package/dist/primitives/String.mjs +44 -13
  54. package/dist/primitives/String.mjs.map +1 -1
  55. package/dist/primitives/Struct.cjs +48 -9
  56. package/dist/primitives/Struct.d.cts +22 -3
  57. package/dist/primitives/Struct.d.cts.map +1 -1
  58. package/dist/primitives/Struct.d.mts +22 -3
  59. package/dist/primitives/Struct.d.mts.map +1 -1
  60. package/dist/primitives/Struct.mjs +48 -9
  61. package/dist/primitives/Struct.mjs.map +1 -1
  62. package/dist/primitives/Union.mjs.map +1 -1
  63. package/dist/primitives/shared.cjs +2 -5
  64. package/dist/primitives/shared.d.cts +2 -4
  65. package/dist/primitives/shared.d.cts.map +1 -1
  66. package/dist/primitives/shared.d.mts +2 -4
  67. package/dist/primitives/shared.d.mts.map +1 -1
  68. package/dist/primitives/shared.mjs +2 -5
  69. package/dist/primitives/shared.mjs.map +1 -1
  70. package/package.json +15 -8
  71. package/src/Document.ts +13 -4
  72. package/src/EffectSchema.ts +3 -3
  73. package/src/FractionalIndex.ts +18 -18
  74. package/src/Operation.ts +5 -5
  75. package/src/OperationDefinition.ts +2 -2
  76. package/src/Presence.ts +3 -3
  77. package/src/SchemaJSON.ts +396 -0
  78. package/src/index.ts +1 -0
  79. package/src/primitives/Array.ts +18 -8
  80. package/src/primitives/Boolean.ts +2 -2
  81. package/src/primitives/Either.ts +2 -2
  82. package/src/primitives/Literal.ts +2 -2
  83. package/src/primitives/Number.ts +44 -22
  84. package/src/primitives/String.ts +61 -34
  85. package/src/primitives/Struct.ts +100 -12
  86. package/src/primitives/Union.ts +1 -1
  87. package/src/primitives/shared.ts +12 -2
  88. package/.turbo/turbo-build.log +0 -270
  89. package/tests/Document.test.ts +0 -557
  90. package/tests/EffectSchema.test.ts +0 -546
  91. package/tests/FractionalIndex.test.ts +0 -377
  92. package/tests/OperationPath.test.ts +0 -151
  93. package/tests/Presence.test.ts +0 -321
  94. package/tests/Primitive.test.ts +0 -381
  95. package/tests/client/ClientDocument.test.ts +0 -1981
  96. package/tests/client/WebSocketTransport.test.ts +0 -1217
  97. package/tests/primitives/Array.test.ts +0 -526
  98. package/tests/primitives/Boolean.test.ts +0 -126
  99. package/tests/primitives/Either.test.ts +0 -707
  100. package/tests/primitives/Lazy.test.ts +0 -143
  101. package/tests/primitives/Literal.test.ts +0 -122
  102. package/tests/primitives/Number.test.ts +0 -133
  103. package/tests/primitives/String.test.ts +0 -128
  104. package/tests/primitives/Struct.test.ts +0 -1044
  105. package/tests/primitives/Tree.test.ts +0 -1139
  106. package/tests/primitives/TreeNode.test.ts +0 -50
  107. package/tests/primitives/Union.test.ts +0 -554
  108. package/tests/server/ServerDocument.test.ts +0 -903
  109. package/tsconfig.build.json +0 -24
  110. package/tsconfig.json +0 -8
  111. package/tsdown.config.ts +0 -18
  112. package/vitest.mts +0 -11
@@ -123,6 +123,8 @@ declare class ValidationError extends Error {
123
123
  interface Validator<T> {
124
124
  readonly validate: (value: T) => boolean;
125
125
  readonly message: string;
126
+ readonly kind?: string;
127
+ readonly params?: unknown;
126
128
  }
127
129
  /**
128
130
  * Runs all validators against a value, throwing ValidationError if any fail.
@@ -131,10 +133,6 @@ declare function runValidators<T>(value: T, validators: readonly {
131
133
  validate: (value: T) => boolean;
132
134
  message: string;
133
135
  }[]): void;
134
- /**
135
- * Returns true if a primitive can represent null as a meaningful value.
136
- * This is used to avoid pruning explicit null values for null-capable scalar unions.
137
- */
138
136
  declare function primitiveAllowsNullValue(primitive: AnyPrimitive): boolean;
139
137
  /**
140
138
  * Checks if an operation is compatible with the given operation definitions.
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.cts","names":[],"sources":["../../src/primitives/shared.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAmBA;;;;;;;AAMwB,UANP,SAMO,CAAA,MAAA,EAAA,MAAA,EAAA,kBAAA,OAAA,GAAA,KAAA,EAAA,oBAAA,OAAA,GAAA,KAAA,EAAA,YAAA,OAAA,EAAA,eAAA,OAAA,CAAA,CAAA;EACA,SAAA,IAAA,EAAA,MAAA;EACG,SAAA,MAAA,EANN,MAMM;EAAY,SAAA,MAAA,EALlB,MAKkB;EAMpB,SAAA,UAAA,EAVM,SAUW;EAEJ,SAAA,YAAA,EAXL,WAWK;EAAyC,SAAA,SAAA,EAVjD,iBAUiD,CAV/B,MAU+B,EAVvB,MAUuB,CAAA;EAAgC,SAAA,SAAA,EATjF,SASiF;EAEpE,SAAA,YAAA,EAVV,YAUU;;;;;AAqBrB,UAzBG,iBAyBH,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;EACA;EACP,SAAA,WAAA,EAAA,CAAA,GAAA,EAzBuB,gBAyBvB,EAAA,IAAA,EAzBgE,aAyBhE,EAAA,GAzBgG,MAyBhG;EAAyB;EAMpB,SAAA,cAAY,EAAA,CAAA,KAAG,EA7BQ,MA6BC,GAAA,SAAA,EAAA,SAAA,EA7B8B,SA6B9B,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,EAAA,GA7BqE,MA6BrE;EAKxB;EAKA,SAAA,eAAU,EAAA,GAAM,GArCM,MAqCI,GAAS,SAAA;EAMnC;;;;;AASZ;;;EAEE,SAAA,sBAAA,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GA7CsD,MA6CtD;EAAC;AAQH;;;;;;;EAAiK,S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A,GAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,EAAA,KAAA,EAAA,CAAA,GAAA,CAAA,GAtIpC,CAsIoC,SAAA;EAC3B,YAAA,EAAA,KAAA,EAAA;CACe,GAAA,CAAA,GAAA,KAAA;;;;;;KAhId,4EAA4E,0BAA0B,4BAA4B,SAAS,KAAK,IAAI;KAEpJ,cAAc;;;;;;KAOd,wEAAwE,yBAAyB,4BAA4B,IAAI,SAAS,KAAK,SAAS;;;;;KAMxJ,mBAAmB,UAAU;;;;;;KAO7B,gBAAgB,UAAU;;;;KAK1B,eAAe,UAAU;;;;;KAMzB,gBAAgB,UAAU;cAOzB,eAAA,SAAwB,KAAA;;;;;;;UAepB;6BACY;;;;;;;;iBAUf,wBAAwB;oBAA4C;;;iBAoBpE,wBAAA,YAAoC;;;;;;;iBAmBpC,qBAAA,YAAiC,gDAA0D,eAAe;;;;;;;;;;;;;iBAqB1G,wBAAwB,yBAC3B,UACJ,QAAQ,WAAW,MACzB,WAAW"}
@@ -123,6 +123,8 @@ declare class ValidationError extends Error {
123
123
  interface Validator<T> {
124
124
  readonly validate: (value: T) => boolean;
125
125
  readonly message: string;
126
+ readonly kind?: string;
127
+ readonly params?: unknown;
126
128
  }
127
129
  /**
128
130
  * Runs all validators against a value, throwing ValidationError if any fail.
@@ -131,10 +133,6 @@ declare function runValidators<T>(value: T, validators: readonly {
131
133
  validate: (value: T) => boolean;
132
134
  message: string;
133
135
  }[]): void;
134
- /**
135
- * Returns true if a primitive can represent null as a meaningful value.
136
- * This is used to avoid pruning explicit null values for null-capable scalar unions.
137
- */
138
136
  declare function primitiveAllowsNullValue(primitive: AnyPrimitive): boolean;
139
137
  /**
140
138
  * Checks if an operation is compatible with the given operation definitions.
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.mts","names":[],"sources":["../../src/primitives/shared.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAmBA;;;;;;;AAMwB,UANP,SAMO,CAAA,MAAA,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AK,SAAS;;;;;KAMxJ,mBAAmB,UAAU;;;;;;KAO7B,gBAAgB,UAAU;;;;KAK1B,eAAe,UAAU;;;;;KAMzB,gBAAgB,UAAU;cAOzB,eAAA,SAAwB,KAAA;;;;;;;UAepB;6BACY;;;;;;;;iBAUf,wBAAwB;oBAA4C;;;iBAoBpE,wBAAA,YAAoC;;;;;;;iBAmBpC,qBAAA,YAAiC,gDAA0D,eAAe;;;;;;;;;;;;;iBAqB1G,wBAAwB,yBAC3B,UACJ,QAAQ,WAAW,MACzB,WAAW"}
@@ -15,12 +15,9 @@ var ValidationError = class extends Error {
15
15
  function runValidators(value, validators) {
16
16
  for (const validator of validators) if (!validator.validate(value)) throw new ValidationError(validator.message);
17
17
  }
18
- /**
19
- * Returns true if a primitive can represent null as a meaningful value.
20
- * This is used to avoid pruning explicit null values for null-capable scalar unions.
21
- */
18
+ const isLiteralPrimitive = (primitive) => primitive._tag === "LiteralPrimitive" && "literal" in primitive;
22
19
  function primitiveAllowsNullValue(primitive) {
23
- if (primitive._tag === "LiteralPrimitive") return primitive.literal === null;
20
+ if (isLiteralPrimitive(primitive)) return primitive.literal === null;
24
21
  if (primitive._tag === "EitherPrimitive") {
25
22
  var _schema;
26
23
  const variants = (_schema = primitive._schema) === null || _schema === void 0 ? void 0 : _schema.variants;
@@ -1 +1 @@
1
- {"version":3,"file":"shared.mjs","names":["result: Record<string, unknown>","matchingVariantKey: string | undefined"],"sources":["../../src/primitives/shared.ts"],"sourcesContent":["import * as Operation from \"../Operation\";\nimport * as OperationDefinition from \"../OperationDefinition\";\nimport * as ProxyEnvironment from \"../ProxyEnvironment\";\nimport * as OperationPath from \"../OperationPath\";\nimport * as Transform from \"../Transform\";\n\n// =============================================================================\n// Primitive Interface & Type Utilities\n// =============================================================================\n\n/**\n * Base interface that all primitives must implement.\n * Provides type inference helpers and internal operations.\n * \n * @typeParam TState - The state type this primitive holds\n * @typeParam TProxy - The proxy type for interacting with this primitive\n * @typeParam TDefined - Whether the value is guaranteed to be defined (via required() or default())\n * @typeParam THasDefault - Whether this primitive has a default value\n */\nexport interface Primitive<TState, TProxy, TRequired extends boolean = false, THasDefault extends boolean = false, TSetInput = unknown, TUpdateInput = unknown> {\n readonly _tag: string;\n readonly _State: TState;\n readonly _Proxy: TProxy;\n readonly _TRequired: TRequired;\n readonly _THasDefault: THasDefault;\n readonly _internal: PrimitiveInternal<TState, TProxy>;\n readonly TSetInput: TSetInput;\n readonly TUpdateInput: TUpdateInput;\n }\n \n /**\n * Internal operations that each primitive must provide.\n */\n export interface PrimitiveInternal<TState, TProxy> {\n /** Creates a proxy for generating operations */\n readonly createProxy: (env: ProxyEnvironment.ProxyEnvironment, path: OperationPath.OperationPath) => TProxy;\n /** Applies an operation to the current state, returning the new state */\n readonly applyOperation: (state: TState | undefined, operation: Operation.Operation<any, any, any>) => TState;\n /** Returns the initial/default state for this primitive */\n readonly getInitialState: () => TState | undefined;\n /**\n * Converts a set input value to state format.\n * For most primitives, this is a simple pass-through with defaults applied.\n * For Tree primitives, this converts nested input to flat TreeState.\n *\n * @param input - The set input value\n * @returns The corresponding state value\n */\n readonly convertSetInputToState?: (input: unknown) => TState;\n /**\n * Transforms a client operation against a server operation.\n * Used for operational transformation (OT) conflict resolution.\n *\n * @param clientOp - The client's operation to transform\n * @param serverOp - The server's operation that has already been applied\n * @returns TransformResult indicating how the client operation should be handled\n */\n readonly transformOperation: (\n clientOp: Operation.Operation<any, any, any>,\n serverOp: Operation.Operation<any, any, any>\n ) => Transform.TransformResult;\n }\n \n /**\n * Any primitive type - used for generic constraints.\n */\n export type AnyPrimitive = Primitive<any, any, any, any>;\n \n /**\n * Infer the state type from a primitive.\n */\n export type InferState<T> = T extends Primitive<infer S, any, any, any> ? S : never;\n \n /**\n * Infer the proxy type from a primitive.\n */\n export type InferProxy<T> = T extends Primitive<any, infer P, any, any> ? P : never;\n\n /**\n * Infer the SetInput type from a primitive.\n * Works with both Primitive interface types and types with a TSetInput property (like TreeNodePrimitive).\n */\n export type InferSetInput<T> = \n T extends Primitive<any, any, any, any, infer S, any> ? S : \n T extends { TSetInput: infer S } ? S : \n never;\n\n /**\n * Infer the UpdateInput type from a primitive.\n * Works with both Primitive interface types and types with a TUpdateInput property (like TreeNodePrimitive).\n */\n export type InferUpdateInput<T> = \n T extends Primitive<any, any, any, any, any, infer U> ? U : \n T extends { TUpdateInput: infer U } ? U : \n never;\n \n /**\n * Helper type to conditionally add undefined based on TRequired and THasDefault.\n * When TRequired is false and THasDefault is false, the value may be undefined.\n * Otherwise, the value is guaranteed to be defined.\n */\n export type MaybeUndefined<T, TRequired extends boolean, THasDefault extends boolean> = TRequired extends false ? THasDefault extends false ? Optional<T> : T : T;\n\n export type Optional<T> = T | undefined;\n\n /**\n * Helper type to conditionally add undefined based on TRequired and THasDefault.\n * When TRequired is true and THasDefault is false, the value must be provided.\n * Otherwise, the value may be undefined.\n */\n export type NeedsValue<T, TRequired extends boolean, THasDefault extends boolean> = TRequired extends true ? THasDefault extends false ? T : Optional<T> : Optional<T>;\n \n /**\n * Infer the snapshot type from a primitive.\n * The snapshot is a readonly, type-safe structure suitable for rendering.\n */\n export type InferSnapshot<T> = T extends Primitive<any, infer P, any, any>\n ? P extends { toSnapshot(): infer S } ? S : never\n : never;\n\n /**\n * Extract THasDefault from a primitive.\n */\n export type HasDefault<T> = T extends Primitive<any, any, any, infer H> ? H : false;\n\n /**\n * Extract TDefined from a primitive.\n */\n export type IsDefined<T> = T extends Primitive<any, any, infer D, any> ? D : false;\n\n /**\n * Infer whether a primitive is required.\n * Alias for IsDefined for clarity.\n */\n export type IsRequired<T> = IsDefined<T>;\n\n\n // =============================================================================\n // Validation Errors\n // =============================================================================\n \n export class ValidationError extends Error {\n readonly _tag = \"ValidationError\";\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n }\n \n // =============================================================================\n // Validation Infrastructure\n // =============================================================================\n \n /**\n * A validator that checks a value and returns whether it's valid.\n */\n export interface Validator<T> {\n readonly validate: (value: T) => boolean;\n readonly message: string;\n }\n \n\n/**\n * Runs all validators against a value, throwing ValidationError if any fail.\n */\nexport function runValidators<T>(value: T, validators: readonly { validate: (value: T) => boolean; message: string }[]): void {\n for (const validator of validators) {\n if (!validator.validate(value)) {\n throw new ValidationError(validator.message);\n }\n }\n}\n\n/**\n * Returns true if a primitive can represent null as a meaningful value.\n * This is used to avoid pruning explicit null values for null-capable scalar unions.\n */\nexport function primitiveAllowsNullValue(primitive: AnyPrimitive): boolean {\n if (primitive._tag === \"LiteralPrimitive\") {\n return (primitive as { literal: unknown }).literal === null;\n }\n\n if (primitive._tag === \"EitherPrimitive\") {\n const variants = (primitive as { _schema?: { variants?: readonly AnyPrimitive[] } })._schema?.variants;\n return Array.isArray(variants) && variants.some((variant) => primitiveAllowsNullValue(variant));\n }\n\n return false;\n}\n\n/**\n * Checks if an operation is compatible with the given operation definitions.\n * @param operation - The operation to check.\n * @param operationDefinitions - The operation definitions to check against.\n * @returns True if the operation is compatible, false otherwise.\n */\nexport function isCompatibleOperation(operation: Operation.Operation<any, any, any>, operationDefinitions: Record<string, OperationDefinition.OperationDefinition<any, any, any>>) {\n const values = Object.values(operationDefinitions);\n return values.some(value => value.kind === operation.kind);\n}\n\n// =============================================================================\n// Default Value Utilities\n// =============================================================================\n\n/**\n * Applies default values to a partial input, recursively handling nested structs and unions.\n * \n * Uses a two-layer approach:\n * 1. First, get the struct's initial state (which includes struct-level defaults)\n * 2. Then, layer the provided values on top\n * 3. Finally, ensure nested structs and unions are recursively processed\n * \n * @param primitive - The primitive definition containing field information\n * @param value - The partial value provided by the user\n * @returns The value with defaults applied for missing fields\n */\nexport function applyDefaults<T extends AnyPrimitive>(\n primitive: T,\n value: Partial<InferState<T>>\n): InferState<T> {\n // Handle StructPrimitive\n if (primitive._tag === \"StructPrimitive\") {\n const structPrimitive = primitive as unknown as { \n fields: Record<string, AnyPrimitive>;\n _internal: { getInitialState: () => Record<string, unknown> | undefined };\n };\n \n // Start with the struct's initial state (struct-level default or field defaults)\n const structInitialState = structPrimitive._internal.getInitialState() ?? {};\n \n // Layer the provided values on top of initial state\n const result: Record<string, unknown> = { ...structInitialState, ...value };\n const inputObject =\n typeof value === \"object\" && value !== null\n ? (value as Record<string, unknown>)\n : undefined;\n \n for (const key in structPrimitive.fields) {\n const fieldPrimitive = structPrimitive.fields[key]!;\n const hasExplicitKey = inputObject !== undefined && Object.prototype.hasOwnProperty.call(inputObject, key);\n const explicitValue = hasExplicitKey ? inputObject[key] : undefined;\n const fieldDefault = fieldPrimitive._internal.getInitialState();\n const isRequiredWithoutDefault =\n (fieldPrimitive as { _schema?: { required?: boolean } })._schema?.required === true &&\n fieldDefault === undefined;\n\n // Explicit undefined values always prune optional keys.\n // Explicit null values prune optional keys unless null is a valid semantic value for this field.\n // Required fields without defaults reject nullish values.\n const shouldPruneExplicitNullish =\n hasExplicitKey &&\n (\n explicitValue === undefined ||\n (explicitValue === null && !primitiveAllowsNullValue(fieldPrimitive))\n );\n if (shouldPruneExplicitNullish) {\n if (isRequiredWithoutDefault) {\n throw new ValidationError(`Field \"${key}\" is required and cannot be null or undefined`);\n }\n delete result[key];\n continue;\n }\n \n if (!hasExplicitKey && result[key] === undefined) {\n // Field still not provided after merging - try individual field default\n if (fieldDefault !== undefined) {\n result[key] = fieldDefault;\n }\n } else if (\n hasExplicitKey &&\n typeof explicitValue === \"object\" &&\n explicitValue !== null\n ) {\n // Recursively apply defaults to nested structs and unions\n if (fieldPrimitive._tag === \"StructPrimitive\" || fieldPrimitive._tag === \"UnionPrimitive\") {\n result[key] = applyDefaults(fieldPrimitive, explicitValue as Partial<InferState<typeof fieldPrimitive>>);\n }\n }\n }\n \n return result as InferState<T>;\n }\n \n // Handle UnionPrimitive\n if (primitive._tag === \"UnionPrimitive\") {\n const unionPrimitive = primitive as unknown as {\n _schema: {\n discriminator: string;\n variants: Record<string, AnyPrimitive>;\n };\n };\n \n // Validate that value is an object\n if (typeof value !== \"object\" || value === null) {\n return value as InferState<T>;\n }\n \n const discriminator = unionPrimitive._schema.discriminator;\n const discriminatorValue = (value as Record<string, unknown>)[discriminator];\n \n // Find the matching variant based on discriminator value\n let matchingVariantKey: string | undefined;\n for (const variantKey in unionPrimitive._schema.variants) {\n const variant = unionPrimitive._schema.variants[variantKey]!;\n // Variants are structs - check if the discriminator field's literal matches\n if (variant._tag === \"StructPrimitive\") {\n const variantStruct = variant as unknown as {\n fields: Record<string, AnyPrimitive>;\n };\n const discriminatorField = variantStruct.fields[discriminator];\n if (discriminatorField && discriminatorField._tag === \"LiteralPrimitive\") {\n const literalPrimitive = discriminatorField as unknown as { literal: unknown };\n if (literalPrimitive.literal === discriminatorValue) {\n matchingVariantKey = variantKey;\n break;\n }\n }\n }\n }\n \n if (!matchingVariantKey) {\n // No matching variant found - return value as-is\n return value as InferState<T>;\n }\n \n // Apply defaults using the matching variant's struct\n const variantPrimitive = unionPrimitive._schema.variants[matchingVariantKey]!;\n return applyDefaults(variantPrimitive, value as Partial<InferState<typeof variantPrimitive>>) as InferState<T>;\n }\n \n // For other primitives, return the value as-is\n return value as InferState<T>;\n}\n"],"mappings":";;;;AA6IE,IAAa,kBAAb,cAAqC,MAAM;CAEzC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;wBAFP,QAAO;AAGd,OAAK,OAAO;;;;;;AAoBlB,SAAgB,cAAiB,OAAU,YAAmF;AAC5H,MAAK,MAAM,aAAa,WACtB,KAAI,CAAC,UAAU,SAAS,MAAM,CAC5B,OAAM,IAAI,gBAAgB,UAAU,QAAQ;;;;;;AASlD,SAAgB,yBAAyB,WAAkC;AACzE,KAAI,UAAU,SAAS,mBACrB,QAAQ,UAAmC,YAAY;AAGzD,KAAI,UAAU,SAAS,mBAAmB;;EACxC,MAAM,sBAAY,UAAmE,2DAAS;AAC9F,SAAO,MAAM,QAAQ,SAAS,IAAI,SAAS,MAAM,YAAY,yBAAyB,QAAQ,CAAC;;AAGjG,QAAO;;;;;;;;AAST,SAAgB,sBAAsB,WAA+C,sBAA8F;AAEjL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,SAAS,mBAAmB;IAItC,MAAM,qBAHgB,QAGmB,OAAO;AAChD,QAAI,sBAAsB,mBAAmB,SAAS,oBAEpD;SADyB,mBACJ,YAAY,oBAAoB;AACnD,2BAAqB;AACrB;;;;;AAMR,MAAI,CAAC,mBAEH,QAAO;EAIT,MAAM,mBAAmB,eAAe,QAAQ,SAAS;AACzD,SAAO,cAAc,kBAAkB,MAAsD;;AAI/F,QAAO"}
1
+ {"version":3,"file":"shared.mjs","names":["result: Record<string, unknown>","matchingVariantKey: string | undefined"],"sources":["../../src/primitives/shared.ts"],"sourcesContent":["import * as Operation from \"../Operation\";\nimport * as OperationDefinition from \"../OperationDefinition\";\nimport * as ProxyEnvironment from \"../ProxyEnvironment\";\nimport * as OperationPath from \"../OperationPath\";\nimport * as Transform from \"../Transform\";\n\n// =============================================================================\n// Primitive Interface & Type Utilities\n// =============================================================================\n\n/**\n * Base interface that all primitives must implement.\n * Provides type inference helpers and internal operations.\n * \n * @typeParam TState - The state type this primitive holds\n * @typeParam TProxy - The proxy type for interacting with this primitive\n * @typeParam TDefined - Whether the value is guaranteed to be defined (via required() or default())\n * @typeParam THasDefault - Whether this primitive has a default value\n */\nexport interface Primitive<TState, TProxy, TRequired extends boolean = false, THasDefault extends boolean = false, TSetInput = unknown, TUpdateInput = unknown> {\n readonly _tag: string;\n readonly _State: TState;\n readonly _Proxy: TProxy;\n readonly _TRequired: TRequired;\n readonly _THasDefault: THasDefault;\n readonly _internal: PrimitiveInternal<TState, TProxy>;\n readonly TSetInput: TSetInput;\n readonly TUpdateInput: TUpdateInput;\n }\n \n /**\n * Internal operations that each primitive must provide.\n */\n export interface PrimitiveInternal<TState, TProxy> {\n /** Creates a proxy for generating operations */\n readonly createProxy: (env: ProxyEnvironment.ProxyEnvironment, path: OperationPath.OperationPath) => TProxy;\n /** Applies an operation to the current state, returning the new state */\n readonly applyOperation: (state: TState | undefined, operation: Operation.Operation<any, any, any>) => TState;\n /** Returns the initial/default state for this primitive */\n readonly getInitialState: () => TState | undefined;\n /**\n * Converts a set input value to state format.\n * For most primitives, this is a simple pass-through with defaults applied.\n * For Tree primitives, this converts nested input to flat TreeState.\n *\n * @param input - The set input value\n * @returns The corresponding state value\n */\n readonly convertSetInputToState?: (input: unknown) => TState;\n /**\n * Transforms a client operation against a server operation.\n * Used for operational transformation (OT) conflict resolution.\n *\n * @param clientOp - The client's operation to transform\n * @param serverOp - The server's operation that has already been applied\n * @returns TransformResult indicating how the client operation should be handled\n */\n readonly transformOperation: (\n clientOp: Operation.Operation<any, any, any>,\n serverOp: Operation.Operation<any, any, any>\n ) => Transform.TransformResult;\n }\n \n /**\n * Any primitive type - used for generic constraints.\n */\n export type AnyPrimitive = Primitive<any, any, any, any>;\n \n /**\n * Infer the state type from a primitive.\n */\n export type InferState<T> = T extends Primitive<infer S, any, any, any> ? S : never;\n \n /**\n * Infer the proxy type from a primitive.\n */\n export type InferProxy<T> = T extends Primitive<any, infer P, any, any> ? P : never;\n\n /**\n * Infer the SetInput type from a primitive.\n * Works with both Primitive interface types and types with a TSetInput property (like TreeNodePrimitive).\n */\n export type InferSetInput<T> = \n T extends Primitive<any, any, any, any, infer S, any> ? S : \n T extends { TSetInput: infer S } ? S : \n never;\n\n /**\n * Infer the UpdateInput type from a primitive.\n * Works with both Primitive interface types and types with a TUpdateInput property (like TreeNodePrimitive).\n */\n export type InferUpdateInput<T> = \n T extends Primitive<any, any, any, any, any, infer U> ? U : \n T extends { TUpdateInput: infer U } ? U : \n never;\n \n /**\n * Helper type to conditionally add undefined based on TRequired and THasDefault.\n * When TRequired is false and THasDefault is false, the value may be undefined.\n * Otherwise, the value is guaranteed to be defined.\n */\n export type MaybeUndefined<T, TRequired extends boolean, THasDefault extends boolean> = TRequired extends false ? THasDefault extends false ? Optional<T> : T : T;\n\n export type Optional<T> = T | undefined;\n\n /**\n * Helper type to conditionally add undefined based on TRequired and THasDefault.\n * When TRequired is true and THasDefault is false, the value must be provided.\n * Otherwise, the value may be undefined.\n */\n export type NeedsValue<T, TRequired extends boolean, THasDefault extends boolean> = TRequired extends true ? THasDefault extends false ? T : Optional<T> : Optional<T>;\n \n /**\n * Infer the snapshot type from a primitive.\n * The snapshot is a readonly, type-safe structure suitable for rendering.\n */\n export type InferSnapshot<T> = T extends Primitive<any, infer P, any, any>\n ? P extends { toSnapshot(): infer S } ? S : never\n : never;\n\n /**\n * Extract THasDefault from a primitive.\n */\n export type HasDefault<T> = T extends Primitive<any, any, any, infer H> ? H : false;\n\n /**\n * Extract TDefined from a primitive.\n */\n export type IsDefined<T> = T extends Primitive<any, any, infer D, any> ? D : false;\n\n /**\n * Infer whether a primitive is required.\n * Alias for IsDefined for clarity.\n */\n export type IsRequired<T> = IsDefined<T>;\n\n\n // =============================================================================\n // Validation Errors\n // =============================================================================\n \n export class ValidationError extends Error {\n readonly _tag = \"ValidationError\";\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n }\n \n // =============================================================================\n // Validation Infrastructure\n // =============================================================================\n \n /**\n * A validator that checks a value and returns whether it's valid.\n */\n export interface Validator<T> {\n readonly validate: (value: T) => boolean;\n readonly message: string;\n readonly kind?: string;\n readonly params?: unknown;\n }\n \n\n/**\n * Runs all validators against a value, throwing ValidationError if any fail.\n */\nexport function runValidators<T>(value: T, validators: readonly { validate: (value: T) => boolean; message: string }[]): void {\n for (const validator of validators) {\n if (!validator.validate(value)) {\n throw new ValidationError(validator.message);\n }\n }\n}\n\n/**\n * Returns true if a primitive can represent null as a meaningful value.\n * This is used to avoid pruning explicit null values for null-capable scalar unions.\n */\ntype PrimitiveWithLiteral = AnyPrimitive & {\n readonly _tag: \"LiteralPrimitive\";\n readonly literal: unknown;\n};\n\nconst isLiteralPrimitive = (primitive: AnyPrimitive): primitive is PrimitiveWithLiteral =>\n primitive._tag === \"LiteralPrimitive\" && \"literal\" in primitive;\n\nexport function primitiveAllowsNullValue(primitive: AnyPrimitive): boolean {\n if (isLiteralPrimitive(primitive)) {\n return primitive.literal === null;\n }\n\n if (primitive._tag === \"EitherPrimitive\") {\n const variants = (primitive as { _schema?: { variants?: readonly AnyPrimitive[] } })._schema?.variants;\n return Array.isArray(variants) && variants.some((variant) => primitiveAllowsNullValue(variant));\n }\n\n return false;\n}\n\n/**\n * Checks if an operation is compatible with the given operation definitions.\n * @param operation - The operation to check.\n * @param operationDefinitions - The operation definitions to check against.\n * @returns True if the operation is compatible, false otherwise.\n */\nexport function isCompatibleOperation(operation: Operation.Operation<any, any, any>, operationDefinitions: Record<string, OperationDefinition.OperationDefinition<any, any, any>>) {\n const values = Object.values(operationDefinitions);\n return values.some(value => value.kind === operation.kind);\n}\n\n// =============================================================================\n// Default Value Utilities\n// =============================================================================\n\n/**\n * Applies default values to a partial input, recursively handling nested structs and unions.\n * \n * Uses a two-layer approach:\n * 1. First, get the struct's initial state (which includes struct-level defaults)\n * 2. Then, layer the provided values on top\n * 3. Finally, ensure nested structs and unions are recursively processed\n * \n * @param primitive - The primitive definition containing field information\n * @param value - The partial value provided by the user\n * @returns The value with defaults applied for missing fields\n */\nexport function applyDefaults<T extends AnyPrimitive>(\n primitive: T,\n value: Partial<InferState<T>>\n): InferState<T> {\n // Handle StructPrimitive\n if (primitive._tag === \"StructPrimitive\") {\n const structPrimitive = primitive as unknown as { \n fields: Record<string, AnyPrimitive>;\n _internal: { getInitialState: () => Record<string, unknown> | undefined };\n };\n \n // Start with the struct's initial state (struct-level default or field defaults)\n const structInitialState = structPrimitive._internal.getInitialState() ?? {};\n \n // Layer the provided values on top of initial state\n const result: Record<string, unknown> = { ...structInitialState, ...value };\n const inputObject =\n typeof value === \"object\" && value !== null\n ? (value as Record<string, unknown>)\n : undefined;\n \n for (const key in structPrimitive.fields) {\n const fieldPrimitive = structPrimitive.fields[key]!;\n const hasExplicitKey = inputObject !== undefined && Object.prototype.hasOwnProperty.call(inputObject, key);\n const explicitValue = hasExplicitKey ? inputObject[key] : undefined;\n const fieldDefault = fieldPrimitive._internal.getInitialState();\n const isRequiredWithoutDefault =\n (fieldPrimitive as { _schema?: { required?: boolean } })._schema?.required === true &&\n fieldDefault === undefined;\n\n // Explicit undefined values always prune optional keys.\n // Explicit null values prune optional keys unless null is a valid semantic value for this field.\n // Required fields without defaults reject nullish values.\n const shouldPruneExplicitNullish =\n hasExplicitKey &&\n (\n explicitValue === undefined ||\n (explicitValue === null && !primitiveAllowsNullValue(fieldPrimitive))\n );\n if (shouldPruneExplicitNullish) {\n if (isRequiredWithoutDefault) {\n throw new ValidationError(`Field \"${key}\" is required and cannot be null or undefined`);\n }\n delete result[key];\n continue;\n }\n \n if (!hasExplicitKey && result[key] === undefined) {\n // Field still not provided after merging - try individual field default\n if (fieldDefault !== undefined) {\n result[key] = fieldDefault;\n }\n } else if (\n hasExplicitKey &&\n typeof explicitValue === \"object\" &&\n explicitValue !== null\n ) {\n // Recursively apply defaults to nested structs and unions\n if (fieldPrimitive._tag === \"StructPrimitive\" || fieldPrimitive._tag === \"UnionPrimitive\") {\n result[key] = applyDefaults(fieldPrimitive, explicitValue as Partial<InferState<typeof fieldPrimitive>>);\n }\n }\n }\n \n return result as InferState<T>;\n }\n \n // Handle UnionPrimitive\n if (primitive._tag === \"UnionPrimitive\") {\n const unionPrimitive = primitive as unknown as {\n _schema: {\n discriminator: string;\n variants: Record<string, AnyPrimitive>;\n };\n };\n \n // Validate that value is an object\n if (typeof value !== \"object\" || value === null) {\n return value as InferState<T>;\n }\n \n const discriminator = unionPrimitive._schema.discriminator;\n const discriminatorValue = (value as Record<string, unknown>)[discriminator];\n \n // Find the matching variant based on discriminator value\n let matchingVariantKey: string | undefined;\n for (const variantKey in unionPrimitive._schema.variants) {\n const variant = unionPrimitive._schema.variants[variantKey]!;\n // Variants are structs - check if the discriminator field's literal matches\n if (variant._tag === \"StructPrimitive\") {\n const variantStruct = variant as unknown as {\n fields: Record<string, AnyPrimitive>;\n };\n const discriminatorField = variantStruct.fields[discriminator];\n if (discriminatorField && discriminatorField._tag === \"LiteralPrimitive\") {\n const literalPrimitive = discriminatorField as unknown as { literal: unknown };\n if (literalPrimitive.literal === discriminatorValue) {\n matchingVariantKey = variantKey;\n break;\n }\n }\n }\n }\n \n if (!matchingVariantKey) {\n // No matching variant found - return value as-is\n return value as InferState<T>;\n }\n \n // Apply defaults using the matching variant's struct\n const variantPrimitive = unionPrimitive._schema.variants[matchingVariantKey]!;\n return applyDefaults(variantPrimitive, value as Partial<InferState<typeof variantPrimitive>>) as InferState<T>;\n }\n \n // For other primitives, return the value as-is\n return value as InferState<T>;\n}\n"],"mappings":";;;;AA6IE,IAAa,kBAAb,cAAqC,MAAM;CAEzC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;wBAFP,QAAO;AAGd,OAAK,OAAO;;;;;;AAsBlB,SAAgB,cAAiB,OAAU,YAAmF;AAC5H,MAAK,MAAM,aAAa,WACtB,KAAI,CAAC,UAAU,SAAS,MAAM,CAC5B,OAAM,IAAI,gBAAgB,UAAU,QAAQ;;AAclD,MAAM,sBAAsB,cAC1B,UAAU,SAAS,sBAAsB,aAAa;AAExD,SAAgB,yBAAyB,WAAkC;AACzE,KAAI,mBAAmB,UAAU,CAC/B,QAAO,UAAU,YAAY;AAG/B,KAAI,UAAU,SAAS,mBAAmB;;EACxC,MAAM,sBAAY,UAAmE,2DAAS;AAC9F,SAAO,MAAM,QAAQ,SAAS,IAAI,SAAS,MAAM,YAAY,yBAAyB,QAAQ,CAAC;;AAGjG,QAAO;;;;;;;;AAST,SAAgB,sBAAsB,WAA+C,sBAA8F;AAEjL,QADe,OAAO,OAAO,qBAAqB,CACpC,MAAK,UAAS,MAAM,SAAS,UAAU,KAAK;;;;;;;;;;;;;;AAmB5D,SAAgB,cACd,WACA,OACe;AAEf,KAAI,UAAU,SAAS,mBAAmB;;EACxC,MAAM,kBAAkB;EASxB,MAAMA,oEAHqB,gBAAgB,UAAU,iBAAiB,yEAAI,EAAE,GAGR;EACpE,MAAM,cACJ,OAAO,UAAU,YAAY,UAAU,OAClC,QACD;AAEN,OAAK,MAAM,OAAO,gBAAg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"name": "@voidhash/mimic",
3
- "version": "1.0.0-beta.15",
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.15"
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
  }
package/src/Document.ts CHANGED
@@ -115,12 +115,21 @@ export const make = <TSchema extends Primitive.AnyPrimitive>(
115
115
  /**
116
116
  * An ops buffer that maintains a dedup index for O(1) lookups by path:kind.
117
117
  */
118
- const makeOpsBuffer = () => {
119
- let ops: Operation.Operation<any, any, any>[] = [];
118
+ type BufferedOperation = Operation.Operation<any, any, any>;
119
+ interface OpsBuffer {
120
+ push(op: BufferedOperation): void;
121
+ drain(): BufferedOperation[];
122
+ mergeFrom(other: OpsBuffer): void;
123
+ toArray(): readonly BufferedOperation[];
124
+ reset(): void;
125
+ }
126
+
127
+ const makeOpsBuffer = (): OpsBuffer => {
128
+ let ops: BufferedOperation[] = [];
120
129
  // Maps "encodedPath:kind" → array index for deduplicable ops
121
130
  let index = new Map<string, number>();
122
131
 
123
- const dedupKey = (op: Operation.Operation<any, any, any>): string =>
132
+ const dedupKey = (op: BufferedOperation): string =>
124
133
  `${OperationPath.encode(op.path)}:${String(op.kind)}`;
125
134
 
126
135
  return {
@@ -151,7 +160,7 @@ export const make = <TSchema extends Primitive.AnyPrimitive>(
151
160
  return result;
152
161
  },
153
162
  /** Appends all ops from another buffer (used on tx commit). */
154
- mergeFrom(other: ReturnType<typeof makeOpsBuffer>): void {
163
+ mergeFrom(other: OpsBuffer): void {
155
164
  for (const op of other.toArray()) {
156
165
  this.push(op);
157
166
  }
@@ -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;