@orpc/shared 2.0.0-beta.47 → 2.0.0-beta.49

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 (50) hide show
  1. package/README.md +6 -7
  2. package/dist/args.d.ts +2 -0
  3. package/dist/args.js +3 -0
  4. package/dist/array.d.ts +2 -0
  5. package/dist/array.js +7 -0
  6. package/dist/bigint.d.ts +9 -0
  7. package/dist/bigint.js +19 -0
  8. package/dist/buffer.d.ts +18 -0
  9. package/dist/buffer.js +77 -0
  10. package/dist/compare.d.ts +1 -0
  11. package/dist/compare.js +45 -0
  12. package/dist/consts.d.ts +1 -0
  13. package/dist/consts.js +1 -0
  14. package/dist/error.d.ts +1 -0
  15. package/dist/error.js +3 -0
  16. package/dist/function.d.ts +12 -0
  17. package/dist/function.js +38 -0
  18. package/dist/http.d.ts +29 -0
  19. package/dist/http.js +113 -0
  20. package/dist/id.d.ts +8 -0
  21. package/dist/id.js +13 -0
  22. package/dist/index.d.ts +34 -492
  23. package/dist/index.js +32 -0
  24. package/dist/interceptor.d.ts +60 -0
  25. package/dist/interceptor.js +139 -0
  26. package/dist/iterator.d.ts +56 -0
  27. package/dist/iterator.js +157 -0
  28. package/dist/object.d.ts +60 -0
  29. package/dist/object.js +245 -0
  30. package/dist/plugin.d.ts +12 -0
  31. package/dist/plugin.js +61 -0
  32. package/dist/promise.d.ts +17 -0
  33. package/dist/promise.js +32 -0
  34. package/dist/proxy.d.ts +12 -0
  35. package/dist/proxy.js +24 -0
  36. package/dist/queue.d.ts +16 -0
  37. package/dist/queue.js +79 -0
  38. package/dist/signal.d.ts +18 -0
  39. package/dist/signal.js +85 -0
  40. package/dist/stream.d.ts +48 -0
  41. package/dist/stream.js +155 -0
  42. package/dist/tracing.d.ts +73 -0
  43. package/dist/tracing.js +94 -0
  44. package/dist/types.d.ts +26 -0
  45. package/dist/types.js +1 -0
  46. package/dist/value.d.ts +2 -0
  47. package/dist/value.js +6 -0
  48. package/package.json +17 -20
  49. package/dist/index.d.mts +0 -492
  50. package/dist/index.mjs +0 -1117
@@ -0,0 +1,94 @@
1
+ import { isAbortError } from './error.js';
2
+ const TRACER_SYMBOL = /* @__PURE__ */ Symbol.for('ORPC_TRACER');
3
+ export function setTracer(tracer) {
4
+ ;
5
+ globalThis[TRACER_SYMBOL] = tracer;
6
+ }
7
+ export function getTracer() {
8
+ return globalThis[TRACER_SYMBOL];
9
+ }
10
+ export function startSpan(options) {
11
+ const tracer = getTracer();
12
+ if (!tracer) {
13
+ return undefined;
14
+ }
15
+ if (typeof options === 'string') {
16
+ return tracer.startSpan(options);
17
+ }
18
+ return tracer.startSpan(options.name, options.parent);
19
+ }
20
+ export function recordSpanError(span, error) {
21
+ if (!span) {
22
+ return;
23
+ }
24
+ // DO NOT treat aborted error as error if happen during business logic (assumed)
25
+ span.recordException(isAbortError(error) ? 'info' : 'error', toTracingException(error));
26
+ }
27
+ export function setSpanAttributeIfDefined(span, key, value) {
28
+ if (!span || value === undefined) {
29
+ return;
30
+ }
31
+ span.setAttribute(key, value);
32
+ }
33
+ export function toTracingException(error) {
34
+ if (error instanceof Error) {
35
+ const exception = {
36
+ message: error.message,
37
+ name: error.name,
38
+ stack: error.stack,
39
+ };
40
+ if ('code' in error && (typeof error.code === 'string' || typeof error.code === 'number')) {
41
+ exception.code = error.code;
42
+ }
43
+ return exception;
44
+ }
45
+ return { message: String(error) };
46
+ }
47
+ export function toSpanAttributeValue(data) {
48
+ if (data === undefined) {
49
+ return 'undefined';
50
+ }
51
+ try {
52
+ // oxlint-disable-next-line no-restricted-properties
53
+ return JSON.stringify(data, (_, value) => {
54
+ if (typeof value === 'bigint') {
55
+ return value.toString();
56
+ }
57
+ if (value instanceof Map || value instanceof Set) {
58
+ return Array.from(value);
59
+ }
60
+ return value;
61
+ });
62
+ }
63
+ catch {
64
+ // oxlint-disable-next-line typescript/no-base-to-string
65
+ return String(data);
66
+ }
67
+ }
68
+ export async function runWithSpan(options, fn) {
69
+ const tracer = getTracer();
70
+ if (!tracer) {
71
+ return fn();
72
+ }
73
+ const name = typeof options === 'string' ? options : options.name;
74
+ const parent = typeof options === 'string' ? undefined : options.parent;
75
+ return tracer.startActiveSpan(name, parent, async (span) => {
76
+ try {
77
+ return await fn(span);
78
+ }
79
+ catch (e) {
80
+ recordSpanError(span, e);
81
+ throw e;
82
+ }
83
+ finally {
84
+ span.end();
85
+ }
86
+ });
87
+ }
88
+ export function runInSpanContext(span, fn) {
89
+ const tracer = getTracer();
90
+ if (!span || !tracer) {
91
+ return fn();
92
+ }
93
+ return tracer.withActiveSpan(span, fn);
94
+ }
@@ -0,0 +1,26 @@
1
+ export type IntersectPick<T, U> = Pick<T, keyof T & keyof U>;
2
+ /**
3
+ * Like `Omit`, but distributes over unions and keeps known keys beside index signatures.
4
+ */
5
+ export type DistributiveOmit<T, K extends PropertyKey> = {
6
+ [P in keyof T as P extends K ? never : P]: T[P];
7
+ };
8
+ /**
9
+ * Remove protected/private properties/methods
10
+ */
11
+ export type Public<T> = Pick<T, keyof T>;
12
+ export type PromiseWithError<T, TError> = Promise<T> & {
13
+ __error?: {
14
+ type: TError;
15
+ };
16
+ };
17
+ /**
18
+ * The place where you can config the orpc types.
19
+ *
20
+ * - `ThrowableError` the error type that represent throwable errors should be `Error` or `null | undefined | {}` if you want more strict.
21
+ */
22
+ export interface Registry {
23
+ }
24
+ export type ThrowableError = Registry extends {
25
+ ThrowableError: infer T;
26
+ } ? T : Error;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => T);
2
+ export declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): T extends Value<infer U, any> ? U : never;
package/dist/value.js ADDED
@@ -0,0 +1,6 @@
1
+ export function value(value, ...args) {
2
+ if (typeof value === 'function') {
3
+ return value(...args);
4
+ }
5
+ return value;
6
+ }
package/package.json CHANGED
@@ -1,45 +1,42 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
- "type": "module",
4
- "version": "2.0.0-beta.47",
3
+ "version": "2.0.0-beta.49",
5
4
  "description": "Internal utilities shared across oRPC packages",
6
- "license": "MIT",
7
- "funding": [
8
- "https://github.com/sponsors/dinwwwh",
9
- "https://opencollective.com/middleapi"
5
+ "keywords": [
6
+ "orpc"
10
7
  ],
11
8
  "homepage": "https://orpc.dev",
9
+ "license": "MIT",
12
10
  "repository": {
13
11
  "type": "git",
14
12
  "url": "git+https://github.com/middleapi/orpc.git",
15
13
  "directory": "packages/shared"
16
14
  },
17
- "keywords": [
18
- "orpc"
15
+ "funding": [
16
+ "https://github.com/sponsors/dinwwwh",
17
+ "https://opencollective.com/middleapi"
18
+ ],
19
+ "files": [
20
+ "dist"
19
21
  ],
22
+ "type": "module",
20
23
  "sideEffects": false,
21
24
  "exports": {
22
25
  "./package.json": "./package.json",
23
26
  ".": {
24
- "types": "./dist/index.d.mts",
25
- "import": "./dist/index.mjs",
26
- "default": "./dist/index.mjs"
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
27
30
  }
28
31
  },
29
- "files": [
30
- "dist"
31
- ],
32
32
  "dependencies": {
33
- "@standard-server/shared": "~0.13.0",
34
- "radash": "^12.1.1",
33
+ "@standard-server/shared": "~0.15.0",
35
34
  "type-fest": "^5.10.0"
36
35
  },
37
36
  "devDependencies": {
38
- "arktype": "^2.2.8",
37
+ "arktype": "^2.2.9",
39
38
  "valibot": "^1.5.0",
40
39
  "zod": "^4.6.7"
41
40
  },
42
- "scripts": {
43
- "type:check": "tsc -b"
44
- }
41
+ "scripts": {}
45
42
  }