@milaboratories/pl-client 2.17.6 → 2.17.8
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/_virtual/_rolldown/runtime.cjs +43 -0
- package/dist/_virtual/_rolldown/runtime.js +18 -0
- package/dist/core/PromiseTracker.cjs +33 -33
- package/dist/core/PromiseTracker.cjs.map +1 -1
- package/dist/core/PromiseTracker.d.ts +10 -7
- package/dist/core/PromiseTracker.js +33 -31
- package/dist/core/PromiseTracker.js.map +1 -1
- package/dist/core/StatefulPromise.cjs +60 -61
- package/dist/core/StatefulPromise.cjs.map +1 -1
- package/dist/core/StatefulPromise.js +60 -60
- package/dist/core/StatefulPromise.js.map +1 -1
- package/dist/core/abstract_stream.d.ts +18 -15
- package/dist/core/advisory_locks.cjs +42 -49
- package/dist/core/advisory_locks.cjs.map +1 -1
- package/dist/core/advisory_locks.js +42 -48
- package/dist/core/advisory_locks.js.map +1 -1
- package/dist/core/auth.cjs +10 -15
- package/dist/core/auth.cjs.map +1 -1
- package/dist/core/auth.d.ts +7 -3
- package/dist/core/auth.js +10 -13
- package/dist/core/auth.js.map +1 -1
- package/dist/core/cache.d.ts +11 -7
- package/dist/core/client.cjs +255 -306
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +72 -68
- package/dist/core/client.js +253 -285
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.cjs +81 -99
- package/dist/core/config.cjs.map +1 -1
- package/dist/core/config.d.ts +93 -90
- package/dist/core/config.js +81 -98
- package/dist/core/config.js.map +1 -1
- package/dist/core/default_client.cjs +84 -125
- package/dist/core/default_client.cjs.map +1 -1
- package/dist/core/default_client.d.ts +9 -6
- package/dist/core/default_client.js +78 -103
- package/dist/core/default_client.js.map +1 -1
- package/dist/core/driver.cjs +12 -16
- package/dist/core/driver.cjs.map +1 -1
- package/dist/core/driver.d.ts +18 -14
- package/dist/core/driver.js +12 -15
- package/dist/core/driver.js.map +1 -1
- package/dist/core/error_resource.cjs +5 -4
- package/dist/core/error_resource.cjs.map +1 -1
- package/dist/core/error_resource.js +5 -3
- package/dist/core/error_resource.js.map +1 -1
- package/dist/core/errors.cjs +104 -140
- package/dist/core/errors.cjs.map +1 -1
- package/dist/core/errors.d.ts +34 -30
- package/dist/core/errors.js +102 -137
- package/dist/core/errors.js.map +1 -1
- package/dist/core/final.cjs +63 -89
- package/dist/core/final.cjs.map +1 -1
- package/dist/core/final.d.ts +8 -4
- package/dist/core/final.js +63 -87
- package/dist/core/final.js.map +1 -1
- package/dist/core/ll_client.cjs +416 -521
- package/dist/core/ll_client.cjs.map +1 -1
- package/dist/core/ll_client.d.ts +100 -97
- package/dist/core/ll_client.js +415 -519
- package/dist/core/ll_client.js.map +1 -1
- package/dist/core/ll_transaction.cjs +206 -240
- package/dist/core/ll_transaction.cjs.map +1 -1
- package/dist/core/ll_transaction.d.ts +50 -52
- package/dist/core/ll_transaction.js +205 -238
- package/dist/core/ll_transaction.js.map +1 -1
- package/dist/core/stat.cjs +64 -63
- package/dist/core/stat.cjs.map +1 -1
- package/dist/core/stat.d.ts +35 -36
- package/dist/core/stat.js +64 -62
- package/dist/core/stat.js.map +1 -1
- package/dist/core/transaction.cjs +613 -650
- package/dist/core/transaction.cjs.map +1 -1
- package/dist/core/transaction.d.ts +165 -162
- package/dist/core/transaction.js +612 -648
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/type_conversion.cjs +62 -83
- package/dist/core/type_conversion.cjs.map +1 -1
- package/dist/core/type_conversion.js +61 -81
- package/dist/core/type_conversion.js.map +1 -1
- package/dist/core/types.cjs +56 -86
- package/dist/core/types.cjs.map +1 -1
- package/dist/core/types.d.ts +63 -62
- package/dist/core/types.js +54 -83
- package/dist/core/types.js.map +1 -1
- package/dist/core/unauth_client.cjs +35 -41
- package/dist/core/unauth_client.cjs.map +1 -1
- package/dist/core/unauth_client.d.ts +18 -14
- package/dist/core/unauth_client.js +34 -39
- package/dist/core/unauth_client.js.map +1 -1
- package/dist/core/websocket_stream.cjs +277 -349
- package/dist/core/websocket_stream.cjs.map +1 -1
- package/dist/core/websocket_stream.js +275 -347
- package/dist/core/websocket_stream.js.map +1 -1
- package/dist/core/wire.d.ts +21 -17
- package/dist/helpers/pl.cjs +71 -73
- package/dist/helpers/pl.cjs.map +1 -1
- package/dist/helpers/pl.d.ts +40 -41
- package/dist/helpers/pl.js +66 -46
- package/dist/helpers/pl.js.map +1 -1
- package/dist/helpers/poll.cjs +99 -134
- package/dist/helpers/poll.cjs.map +1 -1
- package/dist/helpers/poll.d.ts +37 -34
- package/dist/helpers/poll.js +97 -113
- package/dist/helpers/poll.js.map +1 -1
- package/dist/helpers/retry_strategy.cjs +82 -87
- package/dist/helpers/retry_strategy.cjs.map +1 -1
- package/dist/helpers/retry_strategy.js +83 -86
- package/dist/helpers/retry_strategy.js.map +1 -1
- package/dist/helpers/tx_helpers.cjs +21 -20
- package/dist/helpers/tx_helpers.cjs.map +1 -1
- package/dist/helpers/tx_helpers.d.ts +11 -7
- package/dist/helpers/tx_helpers.js +20 -18
- package/dist/helpers/tx_helpers.js.map +1 -1
- package/dist/index.cjs +117 -106
- package/dist/index.d.ts +17 -17
- package/dist/index.js +17 -19
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs +72 -66
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -1
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts +35 -37
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js +71 -64
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +12611 -12866
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +226 -226
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +281 -330
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +225 -224
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +2640 -4294
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js +12608 -12706
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +1230 -1089
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +393 -420
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +1228 -1083
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +142 -143
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +62 -64
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +140 -141
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +572 -487
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +125 -228
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +572 -485
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/any.cjs +131 -146
- package/dist/proto-grpc/google/protobuf/any.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/any.d.ts +78 -84
- package/dist/proto-grpc/google/protobuf/any.js +130 -144
- package/dist/proto-grpc/google/protobuf/any.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.cjs +92 -100
- package/dist/proto-grpc/google/protobuf/duration.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts +38 -43
- package/dist/proto-grpc/google/protobuf/duration.js +91 -98
- package/dist/proto-grpc/google/protobuf/duration.js.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.cjs +117 -128
- package/dist/proto-grpc/google/protobuf/timestamp.cjs.map +1 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts +50 -55
- package/dist/proto-grpc/google/protobuf/timestamp.js +116 -126
- package/dist/proto-grpc/google/protobuf/timestamp.js.map +1 -1
- package/dist/proto-grpc/google/rpc/code.cjs +223 -238
- package/dist/proto-grpc/google/rpc/code.cjs.map +1 -1
- package/dist/proto-grpc/google/rpc/code.d.ts +209 -206
- package/dist/proto-grpc/google/rpc/code.js +221 -237
- package/dist/proto-grpc/google/rpc/code.js.map +1 -1
- package/dist/proto-rest/index.cjs +67 -66
- package/dist/proto-rest/index.cjs.map +1 -1
- package/dist/proto-rest/index.d.ts +24 -18
- package/dist/proto-rest/index.js +61 -65
- package/dist/proto-rest/index.js.map +1 -1
- package/dist/proto-rest/plapi.d.ts +1400 -1477
- package/dist/test/tcp-proxy.cjs +100 -126
- package/dist/test/tcp-proxy.cjs.map +1 -1
- package/dist/test/tcp-proxy.d.ts +17 -13
- package/dist/test/tcp-proxy.js +97 -104
- package/dist/test/tcp-proxy.js.map +1 -1
- package/dist/test/test_config.cjs +145 -194
- package/dist/test/test_config.cjs.map +1 -1
- package/dist/test/test_config.d.ts +34 -30
- package/dist/test/test_config.js +138 -166
- package/dist/test/test_config.js.map +1 -1
- package/dist/util/pl.cjs +4 -3
- package/dist/util/pl.cjs.map +1 -1
- package/dist/util/pl.js +4 -2
- package/dist/util/pl.js.map +1 -1
- package/dist/util/util.cjs +7 -10
- package/dist/util/util.cjs.map +1 -1
- package/dist/util/util.js +7 -9
- package/dist/util/util.js.map +1 -1
- package/package.json +10 -10
- package/src/core/transaction.ts +123 -133
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs +0 -61
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs.map +0 -1
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js +0 -58
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js.map +0 -1
- package/dist/core/PromiseTracker.d.ts.map +0 -1
- package/dist/core/StatefulPromise.d.ts +0 -39
- package/dist/core/StatefulPromise.d.ts.map +0 -1
- package/dist/core/abstract_stream.d.ts.map +0 -1
- package/dist/core/advisory_locks.d.ts +0 -10
- package/dist/core/advisory_locks.d.ts.map +0 -1
- package/dist/core/auth.d.ts.map +0 -1
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/default_client.d.ts.map +0 -1
- package/dist/core/driver.d.ts.map +0 -1
- package/dist/core/error_resource.d.ts +0 -6
- package/dist/core/error_resource.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/final.d.ts.map +0 -1
- package/dist/core/ll_client.d.ts.map +0 -1
- package/dist/core/ll_transaction.d.ts.map +0 -1
- package/dist/core/stat.d.ts.map +0 -1
- package/dist/core/transaction.d.ts.map +0 -1
- package/dist/core/type_conversion.d.ts +0 -8
- package/dist/core/type_conversion.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/unauth_client.d.ts.map +0 -1
- package/dist/core/websocket_stream.d.ts +0 -67
- package/dist/core/websocket_stream.d.ts.map +0 -1
- package/dist/core/wire.d.ts.map +0 -1
- package/dist/helpers/pl.d.ts.map +0 -1
- package/dist/helpers/poll.d.ts.map +0 -1
- package/dist/helpers/retry_strategy.d.ts +0 -24
- package/dist/helpers/retry_strategy.d.ts.map +0 -1
- package/dist/helpers/state_helpers.d.ts +0 -3
- package/dist/helpers/state_helpers.d.ts.map +0 -1
- package/dist/helpers/tx_helpers.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/proto-grpc/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -106
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts +0 -73
- package/dist/proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/ws-test.d.ts.map +0 -1
- package/dist/proto-grpc/google/api/http.d.ts +0 -456
- package/dist/proto-grpc/google/api/http.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/any.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts +0 -2340
- package/dist/proto-grpc/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/empty.d.ts +0 -32
- package/dist/proto-grpc/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/struct.d.ts +0 -187
- package/dist/proto-grpc/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto-grpc/google/protobuf/wrappers.d.ts +0 -308
- package/dist/proto-grpc/google/protobuf/wrappers.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/code.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/error_details.d.ts +0 -654
- package/dist/proto-grpc/google/rpc/error_details.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/http.d.ts +0 -121
- package/dist/proto-grpc/google/rpc/http.d.ts.map +0 -1
- package/dist/proto-grpc/google/rpc/status.d.ts +0 -55
- package/dist/proto-grpc/google/rpc/status.d.ts.map +0 -1
- package/dist/proto-rest/index.d.ts.map +0 -1
- package/dist/proto-rest/plapi.d.ts.map +0 -1
- package/dist/test/tcp-proxy.d.ts.map +0 -1
- package/dist/test/test_config.d.ts.map +0 -1
- package/dist/util/branding.d.ts +0 -7
- package/dist/util/branding.d.ts.map +0 -1
- package/dist/util/pl.d.ts +0 -9
- package/dist/util/pl.d.ts.map +0 -1
- package/dist/util/util.d.ts +0 -2
- package/dist/util/util.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type_conversion.js","sources":["../../src/core/type_conversion.ts"],"sourcesContent":["import type {\n Field,\n Resource,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types\";\nimport {\n Field_ValueStatus,\n Resource_Kind,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types\";\nimport { FieldType as GrpcFieldType } from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types\";\nimport type {\n FieldData,\n FieldStatus,\n OptionalResourceId,\n FieldType,\n ResourceData,\n ResourceId,\n ResourceKind,\n} from \"./types\";\nimport { NullResourceId } from \"./types\";\nimport { assertNever, notEmpty } from \"@milaboratories/ts-helpers\";\nimport { throwPlNotFoundError } from \"./errors\";\n\nconst ResourceErrorField = \"resourceError\";\n\nfunction resourceIsDeleted(proto: Resource): boolean {\n return proto.deletedTime !== undefined && proto.deletedTime.seconds !== 0n;\n}\n\n/** Throws \"native\" pl not found error, if resource is marked as deleted. */\nexport function protoToResource(proto: Resource): ResourceData {\n if (resourceIsDeleted(proto)) throwPlNotFoundError(\"resource deleted\");\n return {\n id: proto.id as ResourceId,\n originalResourceId: proto.originalResourceId as OptionalResourceId,\n type: notEmpty(proto.type),\n data: proto.data,\n inputsLocked: proto.inputsLocked,\n outputsLocked: proto.outputsLocked,\n resourceReady: proto.resourceReady,\n kind: protoToResourceKind(proto.kind),\n error: protoToError(proto),\n final: proto.isFinal,\n fields: proto.fields?.filter((f) => f.id!.fieldName !== ResourceErrorField).map(protoToField),\n };\n}\n\nfunction protoToResourceKind(proto: Resource_Kind): ResourceKind {\n switch (proto) {\n case Resource_Kind.STRUCTURAL:\n return \"Structural\";\n case Resource_Kind.VALUE:\n return \"Value\";\n }\n\n throw new Error(\"invalid ResourceKind: \" + proto);\n}\n\nfunction protoToError(proto: Resource): OptionalResourceId {\n const f = proto.fields.find((f) => f?.id?.fieldName === ResourceErrorField);\n return (f?.error ?? NullResourceId) as OptionalResourceId;\n}\n\nexport function protoToField(proto: Field): FieldData {\n return {\n name: notEmpty(proto.id?.fieldName),\n type: protoToFieldType(proto.type),\n status: protoToFieldStatus(proto.valueStatus),\n value: proto.value as OptionalResourceId,\n error: proto.error as OptionalResourceId,\n valueIsFinal: proto.valueIsFinal,\n };\n}\n\nfunction protoToFieldType(proto: GrpcFieldType): FieldType {\n switch (proto) {\n case GrpcFieldType.INPUT:\n return \"Input\";\n case GrpcFieldType.OUTPUT:\n return \"Output\";\n case GrpcFieldType.SERVICE:\n return \"Service\";\n case GrpcFieldType.ONE_TIME_WRITABLE:\n return \"OTW\";\n case GrpcFieldType.DYNAMIC:\n return \"Dynamic\";\n case GrpcFieldType.MULTIPLE_TIMES_WRITABLE:\n return \"MTW\";\n default:\n throw new Error(\"invalid FieldType: \" + proto);\n }\n}\n\nfunction protoToFieldStatus(proto: Field_ValueStatus): FieldStatus {\n switch (proto) {\n case Field_ValueStatus.EMPTY:\n return \"Empty\";\n case Field_ValueStatus.ASSIGNED:\n return \"Assigned\";\n case Field_ValueStatus.RESOLVED:\n return \"Resolved\";\n default:\n throw new Error(\"invalid FieldStatus: \" + proto);\n }\n}\n\nexport function fieldTypeToProto(type: FieldType): GrpcFieldType {\n switch (type) {\n case \"Input\":\n return GrpcFieldType.INPUT;\n case \"Output\":\n return GrpcFieldType.OUTPUT;\n case \"Dynamic\":\n return GrpcFieldType.DYNAMIC;\n case \"Service\":\n return GrpcFieldType.SERVICE;\n case \"MTW\":\n return GrpcFieldType.MULTIPLE_TIMES_WRITABLE;\n case \"OTW\":\n return GrpcFieldType.ONE_TIME_WRITABLE;\n default:\n return assertNever(type);\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"type_conversion.js","names":["GrpcFieldType"],"sources":["../../src/core/type_conversion.ts"],"sourcesContent":["import type {\n Field,\n Resource,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types\";\nimport {\n Field_ValueStatus,\n Resource_Kind,\n} from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/api_types\";\nimport { FieldType as GrpcFieldType } from \"../proto-grpc/github.com/milaboratory/pl/plapi/plapiproto/base_types\";\nimport type {\n FieldData,\n FieldStatus,\n OptionalResourceId,\n FieldType,\n ResourceData,\n ResourceId,\n ResourceKind,\n} from \"./types\";\nimport { NullResourceId } from \"./types\";\nimport { assertNever, notEmpty } from \"@milaboratories/ts-helpers\";\nimport { throwPlNotFoundError } from \"./errors\";\n\nconst ResourceErrorField = \"resourceError\";\n\nfunction resourceIsDeleted(proto: Resource): boolean {\n return proto.deletedTime !== undefined && proto.deletedTime.seconds !== 0n;\n}\n\n/** Throws \"native\" pl not found error, if resource is marked as deleted. */\nexport function protoToResource(proto: Resource): ResourceData {\n if (resourceIsDeleted(proto)) throwPlNotFoundError(\"resource deleted\");\n return {\n id: proto.id as ResourceId,\n originalResourceId: proto.originalResourceId as OptionalResourceId,\n type: notEmpty(proto.type),\n data: proto.data,\n inputsLocked: proto.inputsLocked,\n outputsLocked: proto.outputsLocked,\n resourceReady: proto.resourceReady,\n kind: protoToResourceKind(proto.kind),\n error: protoToError(proto),\n final: proto.isFinal,\n fields: proto.fields?.filter((f) => f.id!.fieldName !== ResourceErrorField).map(protoToField),\n };\n}\n\nfunction protoToResourceKind(proto: Resource_Kind): ResourceKind {\n switch (proto) {\n case Resource_Kind.STRUCTURAL:\n return \"Structural\";\n case Resource_Kind.VALUE:\n return \"Value\";\n }\n\n throw new Error(\"invalid ResourceKind: \" + proto);\n}\n\nfunction protoToError(proto: Resource): OptionalResourceId {\n const f = proto.fields.find((f) => f?.id?.fieldName === ResourceErrorField);\n return (f?.error ?? NullResourceId) as OptionalResourceId;\n}\n\nexport function protoToField(proto: Field): FieldData {\n return {\n name: notEmpty(proto.id?.fieldName),\n type: protoToFieldType(proto.type),\n status: protoToFieldStatus(proto.valueStatus),\n value: proto.value as OptionalResourceId,\n error: proto.error as OptionalResourceId,\n valueIsFinal: proto.valueIsFinal,\n };\n}\n\nfunction protoToFieldType(proto: GrpcFieldType): FieldType {\n switch (proto) {\n case GrpcFieldType.INPUT:\n return \"Input\";\n case GrpcFieldType.OUTPUT:\n return \"Output\";\n case GrpcFieldType.SERVICE:\n return \"Service\";\n case GrpcFieldType.ONE_TIME_WRITABLE:\n return \"OTW\";\n case GrpcFieldType.DYNAMIC:\n return \"Dynamic\";\n case GrpcFieldType.MULTIPLE_TIMES_WRITABLE:\n return \"MTW\";\n default:\n throw new Error(\"invalid FieldType: \" + proto);\n }\n}\n\nfunction protoToFieldStatus(proto: Field_ValueStatus): FieldStatus {\n switch (proto) {\n case Field_ValueStatus.EMPTY:\n return \"Empty\";\n case Field_ValueStatus.ASSIGNED:\n return \"Assigned\";\n case Field_ValueStatus.RESOLVED:\n return \"Resolved\";\n default:\n throw new Error(\"invalid FieldStatus: \" + proto);\n }\n}\n\nexport function fieldTypeToProto(type: FieldType): GrpcFieldType {\n switch (type) {\n case \"Input\":\n return GrpcFieldType.INPUT;\n case \"Output\":\n return GrpcFieldType.OUTPUT;\n case \"Dynamic\":\n return GrpcFieldType.DYNAMIC;\n case \"Service\":\n return GrpcFieldType.SERVICE;\n case \"MTW\":\n return GrpcFieldType.MULTIPLE_TIMES_WRITABLE;\n case \"OTW\":\n return GrpcFieldType.ONE_TIME_WRITABLE;\n default:\n return assertNever(type);\n }\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,qBAAqB;AAE3B,SAAS,kBAAkB,OAA0B;AACnD,QAAO,MAAM,gBAAgB,UAAa,MAAM,YAAY,YAAY;;;AAI1E,SAAgB,gBAAgB,OAA+B;AAC7D,KAAI,kBAAkB,MAAM,CAAE,sBAAqB,mBAAmB;AACtE,QAAO;EACL,IAAI,MAAM;EACV,oBAAoB,MAAM;EAC1B,MAAM,SAAS,MAAM,KAAK;EAC1B,MAAM,MAAM;EACZ,cAAc,MAAM;EACpB,eAAe,MAAM;EACrB,eAAe,MAAM;EACrB,MAAM,oBAAoB,MAAM,KAAK;EACrC,OAAO,aAAa,MAAM;EAC1B,OAAO,MAAM;EACb,QAAQ,MAAM,QAAQ,QAAQ,MAAM,EAAE,GAAI,cAAc,mBAAmB,CAAC,IAAI,aAAa;EAC9F;;AAGH,SAAS,oBAAoB,OAAoC;AAC/D,SAAQ,OAAR;EACE,KAAK,cAAc,WACjB,QAAO;EACT,KAAK,cAAc,MACjB,QAAO;;AAGX,OAAM,IAAI,MAAM,2BAA2B,MAAM;;AAGnD,SAAS,aAAa,OAAqC;AAEzD,QADU,MAAM,OAAO,MAAM,MAAM,GAAG,IAAI,cAAc,mBAAmB,EAChE,SAAS;;AAGtB,SAAgB,aAAa,OAAyB;AACpD,QAAO;EACL,MAAM,SAAS,MAAM,IAAI,UAAU;EACnC,MAAM,iBAAiB,MAAM,KAAK;EAClC,QAAQ,mBAAmB,MAAM,YAAY;EAC7C,OAAO,MAAM;EACb,OAAO,MAAM;EACb,cAAc,MAAM;EACrB;;AAGH,SAAS,iBAAiB,OAAiC;AACzD,SAAQ,OAAR;EACE,KAAKA,UAAc,MACjB,QAAO;EACT,KAAKA,UAAc,OACjB,QAAO;EACT,KAAKA,UAAc,QACjB,QAAO;EACT,KAAKA,UAAc,kBACjB,QAAO;EACT,KAAKA,UAAc,QACjB,QAAO;EACT,KAAKA,UAAc,wBACjB,QAAO;EACT,QACE,OAAM,IAAI,MAAM,wBAAwB,MAAM;;;AAIpD,SAAS,mBAAmB,OAAuC;AACjE,SAAQ,OAAR;EACE,KAAK,kBAAkB,MACrB,QAAO;EACT,KAAK,kBAAkB,SACrB,QAAO;EACT,KAAK,kBAAkB,SACrB,QAAO;EACT,QACE,OAAM,IAAI,MAAM,0BAA0B,MAAM;;;AAItD,SAAgB,iBAAiB,MAAgC;AAC/D,SAAQ,MAAR;EACE,KAAK,QACH,QAAOA,UAAc;EACvB,KAAK,SACH,QAAOA,UAAc;EACvB,KAAK,UACH,QAAOA,UAAc;EACvB,KAAK,UACH,QAAOA,UAAc;EACvB,KAAK,MACH,QAAOA,UAAc;EACvB,KAAK,MACH,QAAOA,UAAc;EACvB,QACE,QAAO,YAAY,KAAK"}
|
package/dist/core/types.cjs
CHANGED
|
@@ -1,137 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var tsHelpers = require('@milaboratories/ts-helpers');
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
4
3
|
|
|
4
|
+
//#region src/core/types.ts
|
|
5
5
|
const NullResourceId = 0n;
|
|
6
6
|
function isNullResourceId(resourceId) {
|
|
7
|
-
|
|
7
|
+
return resourceId === NullResourceId;
|
|
8
8
|
}
|
|
9
9
|
function isNotNullResourceId(resourceId) {
|
|
10
|
-
|
|
10
|
+
return resourceId !== NullResourceId;
|
|
11
11
|
}
|
|
12
12
|
function ensureResourceIdNotNull(resourceId) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return resourceId;
|
|
13
|
+
if (!isNotNullResourceId(resourceId)) throw new Error("null resource id");
|
|
14
|
+
return resourceId;
|
|
16
15
|
}
|
|
17
16
|
function isAnyResourceId(resourceId) {
|
|
18
|
-
|
|
17
|
+
return resourceId !== 0n;
|
|
19
18
|
}
|
|
20
19
|
function resourceType(name, version) {
|
|
21
|
-
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
version
|
|
23
|
+
};
|
|
22
24
|
}
|
|
23
25
|
function resourceTypeToString(rt) {
|
|
24
|
-
|
|
26
|
+
return `${rt.name}:${rt.version}`;
|
|
25
27
|
}
|
|
26
28
|
function resourceTypesEqual(type1, type2) {
|
|
27
|
-
|
|
29
|
+
return type1.name === type2.name && type1.version === type2.version;
|
|
28
30
|
}
|
|
29
31
|
function extractBasicResourceData(rd) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
const { id, originalResourceId, kind, type, data, error, inputsLocked, outputsLocked, resourceReady, final } = rd;
|
|
33
|
+
return {
|
|
34
|
+
id,
|
|
35
|
+
originalResourceId,
|
|
36
|
+
kind,
|
|
37
|
+
type,
|
|
38
|
+
data,
|
|
39
|
+
error,
|
|
40
|
+
inputsLocked,
|
|
41
|
+
outputsLocked,
|
|
42
|
+
resourceReady,
|
|
43
|
+
final
|
|
44
|
+
};
|
|
43
45
|
}
|
|
44
46
|
const jsonToData = (data) => Buffer.from(JSON.stringify(data));
|
|
45
|
-
const resDataToJson = (res) =>
|
|
47
|
+
const resDataToJson = (res) => (0, _milaboratories_ts_helpers.cachedDeserialize)((0, _milaboratories_ts_helpers.notEmpty)(res.data));
|
|
46
48
|
function getField(r, name) {
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
//
|
|
50
|
-
// Local / Global ResourceId arithmetics
|
|
51
|
-
//
|
|
52
|
-
// Note: txId and other numerical values are made numbers but not bigint intentionally,
|
|
53
|
-
// after implementing security model based on signed resource ids this will make
|
|
54
|
-
// much more sense
|
|
49
|
+
return (0, _milaboratories_ts_helpers.notEmpty)(r.fields.find((f) => f.name === name));
|
|
50
|
+
}
|
|
55
51
|
const ResourceIdRootMask = 1n << 63n;
|
|
56
52
|
const ResourceIdLocalMask = 1n << 62n;
|
|
57
|
-
const NoFlagsIdMask =
|
|
53
|
+
const NoFlagsIdMask = 4611686018427387903n;
|
|
58
54
|
const LocalResourceIdTxIdOffset = 24n;
|
|
59
|
-
const MaxLocalId =
|
|
60
|
-
const MaxTxId =
|
|
55
|
+
const MaxLocalId = 16777215;
|
|
56
|
+
const MaxTxId = 4294967295;
|
|
61
57
|
/** Mask valid after applying shift */
|
|
62
58
|
const TxIdMask = BigInt(MaxTxId);
|
|
63
59
|
const LocalIdMask = BigInt(MaxLocalId);
|
|
64
|
-
// /** Basically removes embedded tx id */
|
|
65
|
-
// const LocalIdCleanMask = 0xFF00000000FFFFFFn;
|
|
66
60
|
function isRootResourceId(id) {
|
|
67
|
-
|
|
61
|
+
return (id & ResourceIdRootMask) !== 0n;
|
|
68
62
|
}
|
|
69
63
|
function isLocalResourceId(id) {
|
|
70
|
-
|
|
64
|
+
return (id & ResourceIdLocalMask) !== 0n;
|
|
71
65
|
}
|
|
72
66
|
function createLocalResourceId(isRoot, localCounterValue, localTxId) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
localCounterValue < 0 ||
|
|
76
|
-
localTxId <= 0)
|
|
77
|
-
throw Error("wrong local id or tx id");
|
|
78
|
-
return ((isRoot ? ResourceIdRootMask : 0n) |
|
|
79
|
-
ResourceIdLocalMask |
|
|
80
|
-
BigInt(localCounterValue) |
|
|
81
|
-
(BigInt(localTxId) << LocalResourceIdTxIdOffset));
|
|
67
|
+
if (localCounterValue > MaxLocalId || localTxId > MaxTxId || localCounterValue < 0 || localTxId <= 0) throw Error("wrong local id or tx id");
|
|
68
|
+
return (isRoot ? ResourceIdRootMask : 0n) | ResourceIdLocalMask | BigInt(localCounterValue) | BigInt(localTxId) << LocalResourceIdTxIdOffset;
|
|
82
69
|
}
|
|
83
70
|
function createGlobalResourceId(isRoot, unmaskedId) {
|
|
84
|
-
|
|
71
|
+
return (isRoot ? ResourceIdRootMask : 0n) | unmaskedId;
|
|
85
72
|
}
|
|
86
73
|
function extractTxId(localResourceId) {
|
|
87
|
-
|
|
74
|
+
return Number(localResourceId >> LocalResourceIdTxIdOffset & TxIdMask);
|
|
88
75
|
}
|
|
89
76
|
function checkLocalityOfResourceId(resourceId, expectedTxId) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (extractTxId(resourceId) !== expectedTxId)
|
|
93
|
-
throw Error("local id from another transaction, globalize id before leaking it from the transaction");
|
|
77
|
+
if (!isLocalResourceId(resourceId)) return;
|
|
78
|
+
if (extractTxId(resourceId) !== expectedTxId) throw Error("local id from another transaction, globalize id before leaking it from the transaction");
|
|
94
79
|
}
|
|
95
80
|
function resourceIdToString(resourceId) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return ((isRootResourceId(resourceId) ? "R" : "N") +
|
|
100
|
-
"L:0x" +
|
|
101
|
-
(LocalIdMask & resourceId).toString(16) +
|
|
102
|
-
"[0x" +
|
|
103
|
-
extractTxId(resourceId).toString(16) +
|
|
104
|
-
"]");
|
|
105
|
-
else
|
|
106
|
-
return ((isRootResourceId(resourceId) ? "R" : "N") +
|
|
107
|
-
"G:0x" +
|
|
108
|
-
(NoFlagsIdMask & resourceId).toString(16));
|
|
81
|
+
if (isNullResourceId(resourceId)) return "XX:0x0";
|
|
82
|
+
if (isLocalResourceId(resourceId)) return (isRootResourceId(resourceId) ? "R" : "N") + "L:0x" + (LocalIdMask & resourceId).toString(16) + "[0x" + extractTxId(resourceId).toString(16) + "]";
|
|
83
|
+
else return (isRootResourceId(resourceId) ? "R" : "N") + "G:0x" + (NoFlagsIdMask & resourceId).toString(16);
|
|
109
84
|
}
|
|
110
85
|
const resourceIdRegexp = /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\[0x(?<txid>[0-9a-fA-F]+)])?$/;
|
|
111
86
|
function resourceIdFromString(str) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (lg === "L")
|
|
119
|
-
return createLocalResourceId(rn === "R", Number.parseInt(rid, 16), Number.parseInt(txid, 16));
|
|
120
|
-
else
|
|
121
|
-
return createGlobalResourceId(rn === "R", BigInt("0x" + rid));
|
|
87
|
+
const match = str.match(resourceIdRegexp);
|
|
88
|
+
if (match === null) return void 0;
|
|
89
|
+
const { xx, rn, lg, rid, txid } = match.groups;
|
|
90
|
+
if (xx) return NullResourceId;
|
|
91
|
+
if (lg === "L") return createLocalResourceId(rn === "R", Number.parseInt(rid, 16), Number.parseInt(txid, 16));
|
|
92
|
+
else return createGlobalResourceId(rn === "R", BigInt("0x" + rid));
|
|
122
93
|
}
|
|
123
94
|
/** Converts bigint to global resource id */
|
|
124
95
|
function bigintToResourceId(resourceId) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
throw new Error(`Null resource id.`);
|
|
129
|
-
return resourceId;
|
|
96
|
+
if (isLocalResourceId(resourceId)) throw new Error(`Local resource id: ${resourceIdToString(resourceId)}`);
|
|
97
|
+
if (isNullResourceId(resourceId)) throw new Error(`Null resource id.`);
|
|
98
|
+
return resourceId;
|
|
130
99
|
}
|
|
131
100
|
function stringifyWithResourceId(object) {
|
|
132
|
-
|
|
101
|
+
return JSON.stringify(object, (key, value) => typeof value === "bigint" ? resourceIdToString(value) : value);
|
|
133
102
|
}
|
|
134
103
|
|
|
104
|
+
//#endregion
|
|
135
105
|
exports.MaxLocalId = MaxLocalId;
|
|
136
106
|
exports.MaxTxId = MaxTxId;
|
|
137
107
|
exports.NullResourceId = NullResourceId;
|
|
@@ -156,4 +126,4 @@ exports.resourceType = resourceType;
|
|
|
156
126
|
exports.resourceTypeToString = resourceTypeToString;
|
|
157
127
|
exports.resourceTypesEqual = resourceTypesEqual;
|
|
158
128
|
exports.stringifyWithResourceId = stringifyWithResourceId;
|
|
159
|
-
//# sourceMappingURL=types.cjs.map
|
|
129
|
+
//# sourceMappingURL=types.cjs.map
|
package/dist/core/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["../../src/core/types.ts"],"sourcesContent":["import { cachedDeserialize, notEmpty } from \"@milaboratories/ts-helpers\";\n\n// more details here: https://egghead.io/blog/using-branded-types-in-typescript\ndeclare const __resource_id_type__: unique symbol;\ntype BrandResourceId<B> = bigint & { [__resource_id_type__]: B };\n\n/** Global resource id */\nexport type ResourceId = BrandResourceId<\"global\">;\n\n/** Null resource id */\nexport type NullResourceId = BrandResourceId<\"null\">;\n\n/** Local resource id */\nexport type LocalResourceId = BrandResourceId<\"local\">;\n\n/** Any non-null resource id */\nexport type AnyResourceId = ResourceId | LocalResourceId;\n\n/** Any resource id */\nexport type OptionalResourceId = NullResourceId | ResourceId;\n\n/** All possible resource flavours */\nexport type OptionalAnyResourceId = NullResourceId | ResourceId | LocalResourceId;\n\nexport const NullResourceId = 0n as NullResourceId;\n\nexport function isNullResourceId(resourceId: bigint): resourceId is NullResourceId {\n return resourceId === NullResourceId;\n}\n\nexport function isNotNullResourceId(resourceId: OptionalResourceId): resourceId is ResourceId {\n return resourceId !== NullResourceId;\n}\n\nexport function ensureResourceIdNotNull(resourceId: OptionalResourceId): ResourceId {\n if (!isNotNullResourceId(resourceId)) throw new Error(\"null resource id\");\n return resourceId;\n}\n\nexport function isAnyResourceId(resourceId: bigint): resourceId is AnyResourceId {\n return resourceId !== 0n;\n}\n\n// see local / global resource logic below...\n\nexport type ResourceKind = \"Structural\" | \"Value\";\n\nexport type FieldType = \"Input\" | \"Output\" | \"Service\" | \"OTW\" | \"Dynamic\" | \"MTW\";\n\nexport type FutureFieldType = \"Output\" | \"Input\" | \"Service\";\n\nexport type FieldStatus = \"Empty\" | \"Assigned\" | \"Resolved\";\n\nexport interface ResourceType {\n readonly name: string;\n readonly version: string;\n}\n\nexport function resourceType(name: string, version: string): ResourceType {\n return { name, version };\n}\n\nexport function resourceTypeToString(rt: ResourceType): string {\n return `${rt.name}:${rt.version}`;\n}\n\nexport function resourceTypesEqual(type1: ResourceType, type2: ResourceType): boolean {\n return type1.name === type2.name && type1.version === type2.version;\n}\n\n/** Readonly fields here marks properties of resource that can't change according to pl's state machine. */\nexport type BasicResourceData = {\n readonly id: ResourceId;\n readonly originalResourceId: OptionalResourceId;\n\n readonly kind: ResourceKind;\n readonly type: ResourceType;\n\n readonly data?: Uint8Array;\n\n readonly error: OptionalResourceId;\n\n readonly inputsLocked: boolean;\n readonly outputsLocked: boolean;\n readonly resourceReady: boolean;\n\n /** This value is derived from resource state by the server and can be used as\n * a robust criteria to determine resource is in final state. */\n readonly final: boolean;\n};\n\nexport function extractBasicResourceData(rd: ResourceData): BasicResourceData {\n const {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n } = rd;\n return {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n };\n}\n\nexport const jsonToData = (data: unknown) => Buffer.from(JSON.stringify(data));\n\nexport const resDataToJson = (res: ResourceData) => cachedDeserialize(notEmpty(res.data));\n\nexport type ResourceData = BasicResourceData & {\n readonly fields: FieldData[];\n};\n\nexport function getField(r: ResourceData, name: string): FieldData {\n return notEmpty(r.fields.find((f) => f.name === name));\n}\n\nexport type FieldData = {\n readonly name: string;\n readonly type: FieldType;\n readonly status: FieldStatus;\n readonly value: OptionalResourceId;\n readonly error: OptionalResourceId;\n\n /** True if value the fields points to is in final state. */\n readonly valueIsFinal: boolean;\n};\n\n//\n// Local / Global ResourceId arithmetics\n//\n\n// Note: txId and other numerical values are made numbers but not bigint intentionally,\n// after implementing security model based on signed resource ids this will make\n// much more sense\n\nconst ResourceIdRootMask = 1n << 63n;\nconst ResourceIdLocalMask = 1n << 62n;\nconst NoFlagsIdMask = 0x3fffffffffffffffn;\nconst LocalResourceIdTxIdOffset = 24n;\nexport const MaxLocalId = 0xffffff;\nexport const MaxTxId = 0xffffffff;\n/** Mask valid after applying shift */\nconst TxIdMask = BigInt(MaxTxId);\nconst LocalIdMask = BigInt(MaxLocalId);\n\n// /** Basically removes embedded tx id */\n// const LocalIdCleanMask = 0xFF00000000FFFFFFn;\n\nexport function isRootResourceId(id: bigint) {\n return (id & ResourceIdRootMask) !== 0n;\n}\n\nexport function isLocalResourceId(id: bigint): id is LocalResourceId {\n return (id & ResourceIdLocalMask) !== 0n;\n}\n\nexport function createLocalResourceId(\n isRoot: boolean,\n localCounterValue: number,\n localTxId: number,\n): LocalResourceId {\n if (\n localCounterValue > MaxLocalId ||\n localTxId > MaxTxId ||\n localCounterValue < 0 ||\n localTxId <= 0\n )\n throw Error(\"wrong local id or tx id\");\n return ((isRoot ? ResourceIdRootMask : 0n) |\n ResourceIdLocalMask |\n BigInt(localCounterValue) |\n (BigInt(localTxId) << LocalResourceIdTxIdOffset)) as LocalResourceId;\n}\n\nexport function createGlobalResourceId(isRoot: boolean, unmaskedId: bigint): ResourceId {\n return ((isRoot ? ResourceIdRootMask : 0n) | unmaskedId) as ResourceId;\n}\n\nexport function extractTxId(localResourceId: LocalResourceId): number {\n return Number((localResourceId >> LocalResourceIdTxIdOffset) & TxIdMask);\n}\n\nexport function checkLocalityOfResourceId(resourceId: AnyResourceId, expectedTxId: number): void {\n if (!isLocalResourceId(resourceId)) return;\n if (extractTxId(resourceId) !== expectedTxId)\n throw Error(\n \"local id from another transaction, globalize id before leaking it from the transaction\",\n );\n}\n\nexport function resourceIdToString(resourceId: OptionalAnyResourceId): string {\n if (isNullResourceId(resourceId)) return \"XX:0x0\";\n if (isLocalResourceId(resourceId))\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"L:0x\" +\n (LocalIdMask & resourceId).toString(16) +\n \"[0x\" +\n extractTxId(resourceId).toString(16) +\n \"]\"\n );\n else\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"G:0x\" +\n (NoFlagsIdMask & resourceId).toString(16)\n );\n}\n\nconst resourceIdRegexp =\n /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\\[0x(?<txid>[0-9a-fA-F]+)])?$/;\n\nexport function resourceIdFromString(str: string): OptionalAnyResourceId | undefined {\n const match = str.match(resourceIdRegexp);\n if (match === null) return undefined;\n const { xx, rn, lg, rid, txid } = match.groups!;\n if (xx) return NullResourceId;\n if (lg === \"L\")\n return createLocalResourceId(rn === \"R\", Number.parseInt(rid, 16), Number.parseInt(txid, 16));\n else return createGlobalResourceId(rn === \"R\", BigInt(\"0x\" + rid));\n}\n\n/** Converts bigint to global resource id */\nexport function bigintToResourceId(resourceId: bigint): ResourceId {\n if (isLocalResourceId(resourceId))\n throw new Error(`Local resource id: ${resourceIdToString(resourceId)}`);\n if (isNullResourceId(resourceId)) throw new Error(`Null resource id.`);\n return resourceId as ResourceId;\n}\n\nexport function stringifyWithResourceId(object: unknown): string {\n return JSON.stringify(object, (key, value) =>\n typeof value === \"bigint\" ? resourceIdToString(value as OptionalAnyResourceId) : value,\n );\n}\n"],"names":["cachedDeserialize","notEmpty"],"mappings":";;;;AAwBO,MAAM,cAAc,GAAG;AAExB,SAAU,gBAAgB,CAAC,UAAkB,EAAA;IACjD,OAAO,UAAU,KAAK,cAAc;AACtC;AAEM,SAAU,mBAAmB,CAAC,UAA8B,EAAA;IAChE,OAAO,UAAU,KAAK,cAAc;AACtC;AAEM,SAAU,uBAAuB,CAAC,UAA8B,EAAA;AACpE,IAAA,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;AACzE,IAAA,OAAO,UAAU;AACnB;AAEM,SAAU,eAAe,CAAC,UAAkB,EAAA;IAChD,OAAO,UAAU,KAAK,EAAE;AAC1B;AAiBM,SAAU,YAAY,CAAC,IAAY,EAAE,OAAe,EAAA;AACxD,IAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;AAC1B;AAEM,SAAU,oBAAoB,CAAC,EAAgB,EAAA;IACnD,OAAO,CAAA,EAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,CAAA,CAAE;AACnC;AAEM,SAAU,kBAAkB,CAAC,KAAmB,EAAE,KAAmB,EAAA;AACzE,IAAA,OAAO,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;AACrE;AAuBM,SAAU,wBAAwB,CAAC,EAAgB,EAAA;IACvD,MAAM,EACJ,EAAE,EACF,kBAAkB,EAClB,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,KAAK,GACN,GAAG,EAAE;IACN,OAAO;QACL,EAAE;QACF,kBAAkB;QAClB,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,KAAK;QACL,YAAY;QACZ,aAAa;QACb,aAAa;QACb,KAAK;KACN;AACH;MAEa,UAAU,GAAG,CAAC,IAAa,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;AAEtE,MAAM,aAAa,GAAG,CAAC,GAAiB,KAAKA,2BAAiB,CAACC,kBAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;AAMlF,SAAU,QAAQ,CAAC,CAAe,EAAE,IAAY,EAAA;IACpD,OAAOA,kBAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACxD;AAaA;AACA;AACA;AAEA;AACA;AACA;AAEA,MAAM,kBAAkB,GAAG,EAAE,IAAI,GAAG;AACpC,MAAM,mBAAmB,GAAG,EAAE,IAAI,GAAG;AACrC,MAAM,aAAa,GAAG,mBAAmB;AACzC,MAAM,yBAAyB,GAAG,GAAG;AAC9B,MAAM,UAAU,GAAG;AACnB,MAAM,OAAO,GAAG;AACvB;AACA,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC;AAChC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;AAEtC;AACA;AAEM,SAAU,gBAAgB,CAAC,EAAU,EAAA;AACzC,IAAA,OAAO,CAAC,EAAE,GAAG,kBAAkB,MAAM,EAAE;AACzC;AAEM,SAAU,iBAAiB,CAAC,EAAU,EAAA;AAC1C,IAAA,OAAO,CAAC,EAAE,GAAG,mBAAmB,MAAM,EAAE;AAC1C;SAEgB,qBAAqB,CACnC,MAAe,EACf,iBAAyB,EACzB,SAAiB,EAAA;IAEjB,IACE,iBAAiB,GAAG,UAAU;AAC9B,QAAA,SAAS,GAAG,OAAO;AACnB,QAAA,iBAAiB,GAAG,CAAC;AACrB,QAAA,SAAS,IAAI,CAAC;AAEd,QAAA,MAAM,KAAK,CAAC,yBAAyB,CAAC;IACxC,QAAQ,CAAC,MAAM,GAAG,kBAAkB,GAAG,EAAE;QACvC,mBAAmB;QACnB,MAAM,CAAC,iBAAiB,CAAC;SACxB,MAAM,CAAC,SAAS,CAAC,IAAI,yBAAyB,CAAC;AACpD;AAEM,SAAU,sBAAsB,CAAC,MAAe,EAAE,UAAkB,EAAA;AACxE,IAAA,QAAQ,CAAC,MAAM,GAAG,kBAAkB,GAAG,EAAE,IAAI,UAAU;AACzD;AAEM,SAAU,WAAW,CAAC,eAAgC,EAAA;IAC1D,OAAO,MAAM,CAAC,CAAC,eAAe,IAAI,yBAAyB,IAAI,QAAQ,CAAC;AAC1E;AAEM,SAAU,yBAAyB,CAAC,UAAyB,EAAE,YAAoB,EAAA;AACvF,IAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC;QAAE;AACpC,IAAA,IAAI,WAAW,CAAC,UAAU,CAAC,KAAK,YAAY;AAC1C,QAAA,MAAM,KAAK,CACT,wFAAwF,CACzF;AACL;AAEM,SAAU,kBAAkB,CAAC,UAAiC,EAAA;IAClE,IAAI,gBAAgB,CAAC,UAAU,CAAC;AAAE,QAAA,OAAO,QAAQ;IACjD,IAAI,iBAAiB,CAAC,UAAU,CAAC;AAC/B,QAAA,QACE,CAAC,gBAAgB,CAAC,UAAU,CAAC,GAAG,GAAG,GAAG,GAAG;YACzC,MAAM;YACN,CAAC,WAAW,GAAG,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC;YACvC,KAAK;AACL,YAAA,WAAW,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;AACpC,YAAA,GAAG;;AAGL,QAAA,QACE,CAAC,gBAAgB,CAAC,UAAU,CAAC,GAAG,GAAG,GAAG,GAAG;YACzC,MAAM;YACN,CAAC,aAAa,GAAG,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC;AAE/C;AAEA,MAAM,gBAAgB,GACpB,gGAAgG;AAE5F,SAAU,oBAAoB,CAAC,GAAW,EAAA;IAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACzC,IAAI,KAAK,KAAK,IAAI;AAAE,QAAA,OAAO,SAAS;AACpC,IAAA,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAO;AAC/C,IAAA,IAAI,EAAE;AAAE,QAAA,OAAO,cAAc;IAC7B,IAAI,EAAE,KAAK,GAAG;QACZ,OAAO,qBAAqB,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;;AAC1F,QAAA,OAAO,sBAAsB,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;AACpE;AAEA;AACM,SAAU,kBAAkB,CAAC,UAAkB,EAAA;IACnD,IAAI,iBAAiB,CAAC,UAAU,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,CAAA,mBAAA,EAAsB,kBAAkB,CAAC,UAAU,CAAC,CAAA,CAAE,CAAC;IACzE,IAAI,gBAAgB,CAAC,UAAU,CAAC;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,CAAA,iBAAA,CAAmB,CAAC;AACtE,IAAA,OAAO,UAAwB;AACjC;AAEM,SAAU,uBAAuB,CAAC,MAAe,EAAA;AACrD,IAAA,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KACvC,OAAO,KAAK,KAAK,QAAQ,GAAG,kBAAkB,CAAC,KAA8B,CAAC,GAAG,KAAK,CACvF;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/core/types.ts"],"sourcesContent":["import { cachedDeserialize, notEmpty } from \"@milaboratories/ts-helpers\";\n\n// more details here: https://egghead.io/blog/using-branded-types-in-typescript\ndeclare const __resource_id_type__: unique symbol;\ntype BrandResourceId<B> = bigint & { [__resource_id_type__]: B };\n\n/** Global resource id */\nexport type ResourceId = BrandResourceId<\"global\">;\n\n/** Null resource id */\nexport type NullResourceId = BrandResourceId<\"null\">;\n\n/** Local resource id */\nexport type LocalResourceId = BrandResourceId<\"local\">;\n\n/** Any non-null resource id */\nexport type AnyResourceId = ResourceId | LocalResourceId;\n\n/** Any resource id */\nexport type OptionalResourceId = NullResourceId | ResourceId;\n\n/** All possible resource flavours */\nexport type OptionalAnyResourceId = NullResourceId | ResourceId | LocalResourceId;\n\nexport const NullResourceId = 0n as NullResourceId;\n\nexport function isNullResourceId(resourceId: bigint): resourceId is NullResourceId {\n return resourceId === NullResourceId;\n}\n\nexport function isNotNullResourceId(resourceId: OptionalResourceId): resourceId is ResourceId {\n return resourceId !== NullResourceId;\n}\n\nexport function ensureResourceIdNotNull(resourceId: OptionalResourceId): ResourceId {\n if (!isNotNullResourceId(resourceId)) throw new Error(\"null resource id\");\n return resourceId;\n}\n\nexport function isAnyResourceId(resourceId: bigint): resourceId is AnyResourceId {\n return resourceId !== 0n;\n}\n\n// see local / global resource logic below...\n\nexport type ResourceKind = \"Structural\" | \"Value\";\n\nexport type FieldType = \"Input\" | \"Output\" | \"Service\" | \"OTW\" | \"Dynamic\" | \"MTW\";\n\nexport type FutureFieldType = \"Output\" | \"Input\" | \"Service\";\n\nexport type FieldStatus = \"Empty\" | \"Assigned\" | \"Resolved\";\n\nexport interface ResourceType {\n readonly name: string;\n readonly version: string;\n}\n\nexport function resourceType(name: string, version: string): ResourceType {\n return { name, version };\n}\n\nexport function resourceTypeToString(rt: ResourceType): string {\n return `${rt.name}:${rt.version}`;\n}\n\nexport function resourceTypesEqual(type1: ResourceType, type2: ResourceType): boolean {\n return type1.name === type2.name && type1.version === type2.version;\n}\n\n/** Readonly fields here marks properties of resource that can't change according to pl's state machine. */\nexport type BasicResourceData = {\n readonly id: ResourceId;\n readonly originalResourceId: OptionalResourceId;\n\n readonly kind: ResourceKind;\n readonly type: ResourceType;\n\n readonly data?: Uint8Array;\n\n readonly error: OptionalResourceId;\n\n readonly inputsLocked: boolean;\n readonly outputsLocked: boolean;\n readonly resourceReady: boolean;\n\n /** This value is derived from resource state by the server and can be used as\n * a robust criteria to determine resource is in final state. */\n readonly final: boolean;\n};\n\nexport function extractBasicResourceData(rd: ResourceData): BasicResourceData {\n const {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n } = rd;\n return {\n id,\n originalResourceId,\n kind,\n type,\n data,\n error,\n inputsLocked,\n outputsLocked,\n resourceReady,\n final,\n };\n}\n\nexport const jsonToData = (data: unknown) => Buffer.from(JSON.stringify(data));\n\nexport const resDataToJson = (res: ResourceData) => cachedDeserialize(notEmpty(res.data));\n\nexport type ResourceData = BasicResourceData & {\n readonly fields: FieldData[];\n};\n\nexport function getField(r: ResourceData, name: string): FieldData {\n return notEmpty(r.fields.find((f) => f.name === name));\n}\n\nexport type FieldData = {\n readonly name: string;\n readonly type: FieldType;\n readonly status: FieldStatus;\n readonly value: OptionalResourceId;\n readonly error: OptionalResourceId;\n\n /** True if value the fields points to is in final state. */\n readonly valueIsFinal: boolean;\n};\n\n//\n// Local / Global ResourceId arithmetics\n//\n\n// Note: txId and other numerical values are made numbers but not bigint intentionally,\n// after implementing security model based on signed resource ids this will make\n// much more sense\n\nconst ResourceIdRootMask = 1n << 63n;\nconst ResourceIdLocalMask = 1n << 62n;\nconst NoFlagsIdMask = 0x3fffffffffffffffn;\nconst LocalResourceIdTxIdOffset = 24n;\nexport const MaxLocalId = 0xffffff;\nexport const MaxTxId = 0xffffffff;\n/** Mask valid after applying shift */\nconst TxIdMask = BigInt(MaxTxId);\nconst LocalIdMask = BigInt(MaxLocalId);\n\n// /** Basically removes embedded tx id */\n// const LocalIdCleanMask = 0xFF00000000FFFFFFn;\n\nexport function isRootResourceId(id: bigint) {\n return (id & ResourceIdRootMask) !== 0n;\n}\n\nexport function isLocalResourceId(id: bigint): id is LocalResourceId {\n return (id & ResourceIdLocalMask) !== 0n;\n}\n\nexport function createLocalResourceId(\n isRoot: boolean,\n localCounterValue: number,\n localTxId: number,\n): LocalResourceId {\n if (\n localCounterValue > MaxLocalId ||\n localTxId > MaxTxId ||\n localCounterValue < 0 ||\n localTxId <= 0\n )\n throw Error(\"wrong local id or tx id\");\n return ((isRoot ? ResourceIdRootMask : 0n) |\n ResourceIdLocalMask |\n BigInt(localCounterValue) |\n (BigInt(localTxId) << LocalResourceIdTxIdOffset)) as LocalResourceId;\n}\n\nexport function createGlobalResourceId(isRoot: boolean, unmaskedId: bigint): ResourceId {\n return ((isRoot ? ResourceIdRootMask : 0n) | unmaskedId) as ResourceId;\n}\n\nexport function extractTxId(localResourceId: LocalResourceId): number {\n return Number((localResourceId >> LocalResourceIdTxIdOffset) & TxIdMask);\n}\n\nexport function checkLocalityOfResourceId(resourceId: AnyResourceId, expectedTxId: number): void {\n if (!isLocalResourceId(resourceId)) return;\n if (extractTxId(resourceId) !== expectedTxId)\n throw Error(\n \"local id from another transaction, globalize id before leaking it from the transaction\",\n );\n}\n\nexport function resourceIdToString(resourceId: OptionalAnyResourceId): string {\n if (isNullResourceId(resourceId)) return \"XX:0x0\";\n if (isLocalResourceId(resourceId))\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"L:0x\" +\n (LocalIdMask & resourceId).toString(16) +\n \"[0x\" +\n extractTxId(resourceId).toString(16) +\n \"]\"\n );\n else\n return (\n (isRootResourceId(resourceId) ? \"R\" : \"N\") +\n \"G:0x\" +\n (NoFlagsIdMask & resourceId).toString(16)\n );\n}\n\nconst resourceIdRegexp =\n /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\\[0x(?<txid>[0-9a-fA-F]+)])?$/;\n\nexport function resourceIdFromString(str: string): OptionalAnyResourceId | undefined {\n const match = str.match(resourceIdRegexp);\n if (match === null) return undefined;\n const { xx, rn, lg, rid, txid } = match.groups!;\n if (xx) return NullResourceId;\n if (lg === \"L\")\n return createLocalResourceId(rn === \"R\", Number.parseInt(rid, 16), Number.parseInt(txid, 16));\n else return createGlobalResourceId(rn === \"R\", BigInt(\"0x\" + rid));\n}\n\n/** Converts bigint to global resource id */\nexport function bigintToResourceId(resourceId: bigint): ResourceId {\n if (isLocalResourceId(resourceId))\n throw new Error(`Local resource id: ${resourceIdToString(resourceId)}`);\n if (isNullResourceId(resourceId)) throw new Error(`Null resource id.`);\n return resourceId as ResourceId;\n}\n\nexport function stringifyWithResourceId(object: unknown): string {\n return JSON.stringify(object, (key, value) =>\n typeof value === \"bigint\" ? resourceIdToString(value as OptionalAnyResourceId) : value,\n );\n}\n"],"mappings":"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"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,78 +1,79 @@
|
|
|
1
|
+
//#region src/core/types.d.ts
|
|
1
2
|
declare const __resource_id_type__: unique symbol;
|
|
2
3
|
type BrandResourceId<B> = bigint & {
|
|
3
|
-
|
|
4
|
+
[__resource_id_type__]: B;
|
|
4
5
|
};
|
|
5
6
|
/** Global resource id */
|
|
6
|
-
|
|
7
|
+
type ResourceId = BrandResourceId<"global">;
|
|
7
8
|
/** Null resource id */
|
|
8
|
-
|
|
9
|
+
type NullResourceId = BrandResourceId<"null">;
|
|
9
10
|
/** Local resource id */
|
|
10
|
-
|
|
11
|
+
type LocalResourceId = BrandResourceId<"local">;
|
|
11
12
|
/** Any non-null resource id */
|
|
12
|
-
|
|
13
|
+
type AnyResourceId = ResourceId | LocalResourceId;
|
|
13
14
|
/** Any resource id */
|
|
14
|
-
|
|
15
|
+
type OptionalResourceId = NullResourceId | ResourceId;
|
|
15
16
|
/** All possible resource flavours */
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
type OptionalAnyResourceId = NullResourceId | ResourceId | LocalResourceId;
|
|
18
|
+
declare const NullResourceId: NullResourceId;
|
|
19
|
+
declare function isNullResourceId(resourceId: bigint): resourceId is NullResourceId;
|
|
20
|
+
declare function isNotNullResourceId(resourceId: OptionalResourceId): resourceId is ResourceId;
|
|
21
|
+
declare function ensureResourceIdNotNull(resourceId: OptionalResourceId): ResourceId;
|
|
22
|
+
declare function isAnyResourceId(resourceId: bigint): resourceId is AnyResourceId;
|
|
23
|
+
type ResourceKind = "Structural" | "Value";
|
|
24
|
+
type FieldType = "Input" | "Output" | "Service" | "OTW" | "Dynamic" | "MTW";
|
|
25
|
+
type FutureFieldType = "Output" | "Input" | "Service";
|
|
26
|
+
type FieldStatus = "Empty" | "Assigned" | "Resolved";
|
|
27
|
+
interface ResourceType {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly version: string;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
declare function resourceType(name: string, version: string): ResourceType;
|
|
32
|
+
declare function resourceTypeToString(rt: ResourceType): string;
|
|
33
|
+
declare function resourceTypesEqual(type1: ResourceType, type2: ResourceType): boolean;
|
|
33
34
|
/** Readonly fields here marks properties of resource that can't change according to pl's state machine. */
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
type BasicResourceData = {
|
|
36
|
+
readonly id: ResourceId;
|
|
37
|
+
readonly originalResourceId: OptionalResourceId;
|
|
38
|
+
readonly kind: ResourceKind;
|
|
39
|
+
readonly type: ResourceType;
|
|
40
|
+
readonly data?: Uint8Array;
|
|
41
|
+
readonly error: OptionalResourceId;
|
|
42
|
+
readonly inputsLocked: boolean;
|
|
43
|
+
readonly outputsLocked: boolean;
|
|
44
|
+
readonly resourceReady: boolean;
|
|
45
|
+
/** This value is derived from resource state by the server and can be used as
|
|
46
|
+
* a robust criteria to determine resource is in final state. */
|
|
47
|
+
readonly final: boolean;
|
|
47
48
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
declare function extractBasicResourceData(rd: ResourceData): BasicResourceData;
|
|
50
|
+
declare const jsonToData: (data: unknown) => Buffer<ArrayBuffer>;
|
|
51
|
+
declare const resDataToJson: (res: ResourceData) => unknown;
|
|
52
|
+
type ResourceData = BasicResourceData & {
|
|
53
|
+
readonly fields: FieldData[];
|
|
53
54
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
readonly valueIsFinal: boolean;
|
|
55
|
+
declare function getField(r: ResourceData, name: string): FieldData;
|
|
56
|
+
type FieldData = {
|
|
57
|
+
readonly name: string;
|
|
58
|
+
readonly type: FieldType;
|
|
59
|
+
readonly status: FieldStatus;
|
|
60
|
+
readonly value: OptionalResourceId;
|
|
61
|
+
readonly error: OptionalResourceId; /** True if value the fields points to is in final state. */
|
|
62
|
+
readonly valueIsFinal: boolean;
|
|
63
63
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
declare const MaxLocalId = 16777215;
|
|
65
|
+
declare const MaxTxId = 4294967295;
|
|
66
|
+
declare function isRootResourceId(id: bigint): boolean;
|
|
67
|
+
declare function isLocalResourceId(id: bigint): id is LocalResourceId;
|
|
68
|
+
declare function createLocalResourceId(isRoot: boolean, localCounterValue: number, localTxId: number): LocalResourceId;
|
|
69
|
+
declare function createGlobalResourceId(isRoot: boolean, unmaskedId: bigint): ResourceId;
|
|
70
|
+
declare function extractTxId(localResourceId: LocalResourceId): number;
|
|
71
|
+
declare function checkLocalityOfResourceId(resourceId: AnyResourceId, expectedTxId: number): void;
|
|
72
|
+
declare function resourceIdToString(resourceId: OptionalAnyResourceId): string;
|
|
73
|
+
declare function resourceIdFromString(str: string): OptionalAnyResourceId | undefined;
|
|
74
74
|
/** Converts bigint to global resource id */
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
declare function bigintToResourceId(resourceId: bigint): ResourceId;
|
|
76
|
+
declare function stringifyWithResourceId(object: unknown): string;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { AnyResourceId, BasicResourceData, FieldData, FieldStatus, FieldType, FutureFieldType, LocalResourceId, MaxLocalId, MaxTxId, NullResourceId, OptionalAnyResourceId, OptionalResourceId, ResourceData, ResourceId, ResourceKind, ResourceType, bigintToResourceId, checkLocalityOfResourceId, createGlobalResourceId, createLocalResourceId, ensureResourceIdNotNull, extractBasicResourceData, extractTxId, getField, isAnyResourceId, isLocalResourceId, isNotNullResourceId, isNullResourceId, isRootResourceId, jsonToData, resDataToJson, resourceIdFromString, resourceIdToString, resourceType, resourceTypeToString, resourceTypesEqual, stringifyWithResourceId };
|
|
78
79
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/core/types.js
CHANGED
|
@@ -1,134 +1,105 @@
|
|
|
1
|
-
import { cachedDeserialize, notEmpty } from
|
|
1
|
+
import { cachedDeserialize, notEmpty } from "@milaboratories/ts-helpers";
|
|
2
2
|
|
|
3
|
+
//#region src/core/types.ts
|
|
3
4
|
const NullResourceId = 0n;
|
|
4
5
|
function isNullResourceId(resourceId) {
|
|
5
|
-
|
|
6
|
+
return resourceId === NullResourceId;
|
|
6
7
|
}
|
|
7
8
|
function isNotNullResourceId(resourceId) {
|
|
8
|
-
|
|
9
|
+
return resourceId !== NullResourceId;
|
|
9
10
|
}
|
|
10
11
|
function ensureResourceIdNotNull(resourceId) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return resourceId;
|
|
12
|
+
if (!isNotNullResourceId(resourceId)) throw new Error("null resource id");
|
|
13
|
+
return resourceId;
|
|
14
14
|
}
|
|
15
15
|
function isAnyResourceId(resourceId) {
|
|
16
|
-
|
|
16
|
+
return resourceId !== 0n;
|
|
17
17
|
}
|
|
18
18
|
function resourceType(name, version) {
|
|
19
|
-
|
|
19
|
+
return {
|
|
20
|
+
name,
|
|
21
|
+
version
|
|
22
|
+
};
|
|
20
23
|
}
|
|
21
24
|
function resourceTypeToString(rt) {
|
|
22
|
-
|
|
25
|
+
return `${rt.name}:${rt.version}`;
|
|
23
26
|
}
|
|
24
27
|
function resourceTypesEqual(type1, type2) {
|
|
25
|
-
|
|
28
|
+
return type1.name === type2.name && type1.version === type2.version;
|
|
26
29
|
}
|
|
27
30
|
function extractBasicResourceData(rd) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
const { id, originalResourceId, kind, type, data, error, inputsLocked, outputsLocked, resourceReady, final } = rd;
|
|
32
|
+
return {
|
|
33
|
+
id,
|
|
34
|
+
originalResourceId,
|
|
35
|
+
kind,
|
|
36
|
+
type,
|
|
37
|
+
data,
|
|
38
|
+
error,
|
|
39
|
+
inputsLocked,
|
|
40
|
+
outputsLocked,
|
|
41
|
+
resourceReady,
|
|
42
|
+
final
|
|
43
|
+
};
|
|
41
44
|
}
|
|
42
45
|
const jsonToData = (data) => Buffer.from(JSON.stringify(data));
|
|
43
46
|
const resDataToJson = (res) => cachedDeserialize(notEmpty(res.data));
|
|
44
47
|
function getField(r, name) {
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
//
|
|
48
|
-
// Local / Global ResourceId arithmetics
|
|
49
|
-
//
|
|
50
|
-
// Note: txId and other numerical values are made numbers but not bigint intentionally,
|
|
51
|
-
// after implementing security model based on signed resource ids this will make
|
|
52
|
-
// much more sense
|
|
48
|
+
return notEmpty(r.fields.find((f) => f.name === name));
|
|
49
|
+
}
|
|
53
50
|
const ResourceIdRootMask = 1n << 63n;
|
|
54
51
|
const ResourceIdLocalMask = 1n << 62n;
|
|
55
|
-
const NoFlagsIdMask =
|
|
52
|
+
const NoFlagsIdMask = 4611686018427387903n;
|
|
56
53
|
const LocalResourceIdTxIdOffset = 24n;
|
|
57
|
-
const MaxLocalId =
|
|
58
|
-
const MaxTxId =
|
|
54
|
+
const MaxLocalId = 16777215;
|
|
55
|
+
const MaxTxId = 4294967295;
|
|
59
56
|
/** Mask valid after applying shift */
|
|
60
57
|
const TxIdMask = BigInt(MaxTxId);
|
|
61
58
|
const LocalIdMask = BigInt(MaxLocalId);
|
|
62
|
-
// /** Basically removes embedded tx id */
|
|
63
|
-
// const LocalIdCleanMask = 0xFF00000000FFFFFFn;
|
|
64
59
|
function isRootResourceId(id) {
|
|
65
|
-
|
|
60
|
+
return (id & ResourceIdRootMask) !== 0n;
|
|
66
61
|
}
|
|
67
62
|
function isLocalResourceId(id) {
|
|
68
|
-
|
|
63
|
+
return (id & ResourceIdLocalMask) !== 0n;
|
|
69
64
|
}
|
|
70
65
|
function createLocalResourceId(isRoot, localCounterValue, localTxId) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
localCounterValue < 0 ||
|
|
74
|
-
localTxId <= 0)
|
|
75
|
-
throw Error("wrong local id or tx id");
|
|
76
|
-
return ((isRoot ? ResourceIdRootMask : 0n) |
|
|
77
|
-
ResourceIdLocalMask |
|
|
78
|
-
BigInt(localCounterValue) |
|
|
79
|
-
(BigInt(localTxId) << LocalResourceIdTxIdOffset));
|
|
66
|
+
if (localCounterValue > MaxLocalId || localTxId > MaxTxId || localCounterValue < 0 || localTxId <= 0) throw Error("wrong local id or tx id");
|
|
67
|
+
return (isRoot ? ResourceIdRootMask : 0n) | ResourceIdLocalMask | BigInt(localCounterValue) | BigInt(localTxId) << LocalResourceIdTxIdOffset;
|
|
80
68
|
}
|
|
81
69
|
function createGlobalResourceId(isRoot, unmaskedId) {
|
|
82
|
-
|
|
70
|
+
return (isRoot ? ResourceIdRootMask : 0n) | unmaskedId;
|
|
83
71
|
}
|
|
84
72
|
function extractTxId(localResourceId) {
|
|
85
|
-
|
|
73
|
+
return Number(localResourceId >> LocalResourceIdTxIdOffset & TxIdMask);
|
|
86
74
|
}
|
|
87
75
|
function checkLocalityOfResourceId(resourceId, expectedTxId) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (extractTxId(resourceId) !== expectedTxId)
|
|
91
|
-
throw Error("local id from another transaction, globalize id before leaking it from the transaction");
|
|
76
|
+
if (!isLocalResourceId(resourceId)) return;
|
|
77
|
+
if (extractTxId(resourceId) !== expectedTxId) throw Error("local id from another transaction, globalize id before leaking it from the transaction");
|
|
92
78
|
}
|
|
93
79
|
function resourceIdToString(resourceId) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return ((isRootResourceId(resourceId) ? "R" : "N") +
|
|
98
|
-
"L:0x" +
|
|
99
|
-
(LocalIdMask & resourceId).toString(16) +
|
|
100
|
-
"[0x" +
|
|
101
|
-
extractTxId(resourceId).toString(16) +
|
|
102
|
-
"]");
|
|
103
|
-
else
|
|
104
|
-
return ((isRootResourceId(resourceId) ? "R" : "N") +
|
|
105
|
-
"G:0x" +
|
|
106
|
-
(NoFlagsIdMask & resourceId).toString(16));
|
|
80
|
+
if (isNullResourceId(resourceId)) return "XX:0x0";
|
|
81
|
+
if (isLocalResourceId(resourceId)) return (isRootResourceId(resourceId) ? "R" : "N") + "L:0x" + (LocalIdMask & resourceId).toString(16) + "[0x" + extractTxId(resourceId).toString(16) + "]";
|
|
82
|
+
else return (isRootResourceId(resourceId) ? "R" : "N") + "G:0x" + (NoFlagsIdMask & resourceId).toString(16);
|
|
107
83
|
}
|
|
108
84
|
const resourceIdRegexp = /^(?:(?<xx>XX)|(?<rn>[XRN])(?<lg>[XLG])):0x(?<rid>[0-9a-fA-F]+)(?:\[0x(?<txid>[0-9a-fA-F]+)])?$/;
|
|
109
85
|
function resourceIdFromString(str) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (lg === "L")
|
|
117
|
-
return createLocalResourceId(rn === "R", Number.parseInt(rid, 16), Number.parseInt(txid, 16));
|
|
118
|
-
else
|
|
119
|
-
return createGlobalResourceId(rn === "R", BigInt("0x" + rid));
|
|
86
|
+
const match = str.match(resourceIdRegexp);
|
|
87
|
+
if (match === null) return void 0;
|
|
88
|
+
const { xx, rn, lg, rid, txid } = match.groups;
|
|
89
|
+
if (xx) return NullResourceId;
|
|
90
|
+
if (lg === "L") return createLocalResourceId(rn === "R", Number.parseInt(rid, 16), Number.parseInt(txid, 16));
|
|
91
|
+
else return createGlobalResourceId(rn === "R", BigInt("0x" + rid));
|
|
120
92
|
}
|
|
121
93
|
/** Converts bigint to global resource id */
|
|
122
94
|
function bigintToResourceId(resourceId) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
throw new Error(`Null resource id.`);
|
|
127
|
-
return resourceId;
|
|
95
|
+
if (isLocalResourceId(resourceId)) throw new Error(`Local resource id: ${resourceIdToString(resourceId)}`);
|
|
96
|
+
if (isNullResourceId(resourceId)) throw new Error(`Null resource id.`);
|
|
97
|
+
return resourceId;
|
|
128
98
|
}
|
|
129
99
|
function stringifyWithResourceId(object) {
|
|
130
|
-
|
|
100
|
+
return JSON.stringify(object, (key, value) => typeof value === "bigint" ? resourceIdToString(value) : value);
|
|
131
101
|
}
|
|
132
102
|
|
|
103
|
+
//#endregion
|
|
133
104
|
export { MaxLocalId, MaxTxId, NullResourceId, bigintToResourceId, checkLocalityOfResourceId, createGlobalResourceId, createLocalResourceId, ensureResourceIdNotNull, extractBasicResourceData, extractTxId, getField, isAnyResourceId, isLocalResourceId, isNotNullResourceId, isNullResourceId, isRootResourceId, jsonToData, resDataToJson, resourceIdFromString, resourceIdToString, resourceType, resourceTypeToString, resourceTypesEqual, stringifyWithResourceId };
|
|
134
|
-
//# sourceMappingURL=types.js.map
|
|
105
|
+
//# sourceMappingURL=types.js.map
|