@kontsedal/olas-core 0.0.1-rc.0
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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/index.cjs +363 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +178 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +178 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +339 -0
- package/dist/index.mjs.map +1 -0
- package/dist/root-BImHnGj1.mjs +3270 -0
- package/dist/root-BImHnGj1.mjs.map +1 -0
- package/dist/root-Bazp5_Ik.cjs +3347 -0
- package/dist/root-Bazp5_Ik.cjs.map +1 -0
- package/dist/testing.cjs +81 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +56 -0
- package/dist/testing.d.cts.map +1 -0
- package/dist/testing.d.mts +56 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +78 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types-CAMgqCMz.d.mts +816 -0
- package/dist/types-CAMgqCMz.d.mts.map +1 -0
- package/dist/types-emq_lZd7.d.cts +816 -0
- package/dist/types-emq_lZd7.d.cts.map +1 -0
- package/package.json +47 -0
- package/src/__dev__.d.ts +8 -0
- package/src/controller/define.ts +50 -0
- package/src/controller/index.ts +12 -0
- package/src/controller/instance.ts +499 -0
- package/src/controller/root.ts +160 -0
- package/src/controller/types.ts +195 -0
- package/src/devtools.ts +0 -0
- package/src/emitter.ts +79 -0
- package/src/errors.ts +49 -0
- package/src/forms/field.ts +303 -0
- package/src/forms/form-types.ts +130 -0
- package/src/forms/form.ts +640 -0
- package/src/forms/index.ts +2 -0
- package/src/forms/types.ts +1 -0
- package/src/forms/validators.ts +70 -0
- package/src/index.ts +89 -0
- package/src/query/client.ts +934 -0
- package/src/query/define.ts +154 -0
- package/src/query/entry.ts +322 -0
- package/src/query/focus-online.ts +73 -0
- package/src/query/index.ts +3 -0
- package/src/query/infinite.ts +462 -0
- package/src/query/keys.ts +33 -0
- package/src/query/local.ts +113 -0
- package/src/query/mutation.ts +384 -0
- package/src/query/plugin.ts +135 -0
- package/src/query/types.ts +168 -0
- package/src/query/use.ts +321 -0
- package/src/scope.ts +42 -0
- package/src/selection.ts +146 -0
- package/src/signals/index.ts +3 -0
- package/src/signals/readonly.ts +22 -0
- package/src/signals/runtime.ts +115 -0
- package/src/signals/types.ts +31 -0
- package/src/testing.ts +142 -0
- package/src/timing/debounced.ts +32 -0
- package/src/timing/index.ts +2 -0
- package/src/timing/throttled.ts +46 -0
- package/src/utils.ts +13 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Validator } from './types'
|
|
2
|
+
|
|
3
|
+
const isEmpty = (value: unknown): boolean => {
|
|
4
|
+
if (value === undefined || value === null) return true
|
|
5
|
+
if (typeof value === 'string') return value.length === 0
|
|
6
|
+
if (Array.isArray(value)) return value.length === 0
|
|
7
|
+
return false
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Reject empty values (undefined, null, empty string, empty array). */
|
|
11
|
+
export const required =
|
|
12
|
+
<T>(message = 'Required'): Validator<T> =>
|
|
13
|
+
(value) =>
|
|
14
|
+
isEmpty(value) ? message : null
|
|
15
|
+
|
|
16
|
+
/** Reject strings / arrays shorter than `n`. Allows null/undefined (use with `required` to forbid). */
|
|
17
|
+
export const minLength =
|
|
18
|
+
(n: number, message?: string): Validator<string | readonly unknown[]> =>
|
|
19
|
+
(value) => {
|
|
20
|
+
if (value == null) return null
|
|
21
|
+
if (value.length >= n) return null
|
|
22
|
+
return message ?? `Must be at least ${n} characters`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Reject strings / arrays longer than `n`. */
|
|
26
|
+
export const maxLength =
|
|
27
|
+
(n: number, message?: string): Validator<string | readonly unknown[]> =>
|
|
28
|
+
(value) => {
|
|
29
|
+
if (value == null) return null
|
|
30
|
+
if (value.length <= n) return null
|
|
31
|
+
return message ?? `Must be no more than ${n} characters`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Reject numbers less than `n`. */
|
|
35
|
+
export const min =
|
|
36
|
+
(n: number, message?: string): Validator<number> =>
|
|
37
|
+
(value) => {
|
|
38
|
+
if (value == null) return null
|
|
39
|
+
if (value >= n) return null
|
|
40
|
+
return message ?? `Must be at least ${n}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Reject numbers greater than `n`. */
|
|
44
|
+
export const max =
|
|
45
|
+
(n: number, message?: string): Validator<number> =>
|
|
46
|
+
(value) => {
|
|
47
|
+
if (value == null) return null
|
|
48
|
+
if (value <= n) return null
|
|
49
|
+
return message ?? `Must be no more than ${n}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// RFC-5322-light. Pragmatic, not exhaustive — production forms should
|
|
53
|
+
// rely on server-side validation for definitive answers.
|
|
54
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
|
55
|
+
|
|
56
|
+
/** Reject strings that don't look like an email. Empty / null pass (use with `required` to forbid). */
|
|
57
|
+
export const email =
|
|
58
|
+
(message = 'Invalid email address'): Validator<string> =>
|
|
59
|
+
(value) => {
|
|
60
|
+
if (value == null || value === '') return null
|
|
61
|
+
return EMAIL_RE.test(value) ? null : message
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Reject strings that don't match the supplied `RegExp`. */
|
|
65
|
+
export const pattern =
|
|
66
|
+
(re: RegExp, message = 'Invalid format'): Validator<string> =>
|
|
67
|
+
(value) => {
|
|
68
|
+
if (value == null || value === '') return null
|
|
69
|
+
return re.test(value) ? null : message
|
|
70
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Signals
|
|
2
|
+
|
|
3
|
+
// Controller container
|
|
4
|
+
export type {
|
|
5
|
+
AmbientDeps,
|
|
6
|
+
ControllerDef,
|
|
7
|
+
CtrlApi,
|
|
8
|
+
CtrlProps,
|
|
9
|
+
Ctx,
|
|
10
|
+
Field,
|
|
11
|
+
Root,
|
|
12
|
+
RootOptions,
|
|
13
|
+
} from './controller'
|
|
14
|
+
export { createRoot, defineController } from './controller'
|
|
15
|
+
// Errors & devtools
|
|
16
|
+
export type { DebugBus, DebugCacheEntry, DebugEvent } from './devtools'
|
|
17
|
+
|
|
18
|
+
// Emitter
|
|
19
|
+
export type { Emitter } from './emitter'
|
|
20
|
+
export { createEmitter } from './emitter'
|
|
21
|
+
export type { ErrorContext } from './errors'
|
|
22
|
+
// Forms — stdlib validators + debouncedValidator
|
|
23
|
+
export type { Validator } from './forms'
|
|
24
|
+
export { email, max, maxLength, min, minLength, pattern, required } from './forms'
|
|
25
|
+
export { debouncedValidator } from './forms/field'
|
|
26
|
+
export type {
|
|
27
|
+
DeepPartial,
|
|
28
|
+
FieldArray,
|
|
29
|
+
FieldArrayItemErrors,
|
|
30
|
+
FieldArrayOptions,
|
|
31
|
+
FieldArrayValidator,
|
|
32
|
+
FieldArrayValue,
|
|
33
|
+
Form,
|
|
34
|
+
FormErrors,
|
|
35
|
+
FormOptions,
|
|
36
|
+
FormSchema,
|
|
37
|
+
FormValidator,
|
|
38
|
+
FormValue,
|
|
39
|
+
ItemInitial,
|
|
40
|
+
} from './forms/form-types'
|
|
41
|
+
export { defineInfiniteQuery, defineQuery } from './query/define'
|
|
42
|
+
export type {
|
|
43
|
+
InfiniteQuery,
|
|
44
|
+
InfiniteQuerySpec,
|
|
45
|
+
InfiniteQuerySubscription,
|
|
46
|
+
} from './query/infinite'
|
|
47
|
+
export type {
|
|
48
|
+
Mutation,
|
|
49
|
+
MutationConcurrency,
|
|
50
|
+
MutationSpec,
|
|
51
|
+
} from './query/mutation'
|
|
52
|
+
// Query-client plugins (§13.2)
|
|
53
|
+
export type {
|
|
54
|
+
GcEvent,
|
|
55
|
+
InvalidateEvent,
|
|
56
|
+
QueryClientPlugin,
|
|
57
|
+
QueryClientPluginApi,
|
|
58
|
+
RegisteredQuery,
|
|
59
|
+
SetDataEvent,
|
|
60
|
+
} from './query/plugin'
|
|
61
|
+
export { lookupRegisteredQuery } from './query/plugin'
|
|
62
|
+
// Query primitives
|
|
63
|
+
export type {
|
|
64
|
+
AsyncState,
|
|
65
|
+
AsyncStatus,
|
|
66
|
+
DehydratedEntry,
|
|
67
|
+
DehydratedState,
|
|
68
|
+
LocalCache,
|
|
69
|
+
Query,
|
|
70
|
+
QuerySpec,
|
|
71
|
+
QuerySubscription,
|
|
72
|
+
RetryDelay,
|
|
73
|
+
RetryPolicy,
|
|
74
|
+
Snapshot,
|
|
75
|
+
UseOptions,
|
|
76
|
+
} from './query/types'
|
|
77
|
+
// Scopes — typed cross-tree data (§10.3)
|
|
78
|
+
export type { Scope, ScopeOptions } from './scope'
|
|
79
|
+
export { defineScope } from './scope'
|
|
80
|
+
// Selection — multi-select with shift/meta-click semantics (§17.5)
|
|
81
|
+
export type { Selection } from './selection'
|
|
82
|
+
export { selection } from './selection'
|
|
83
|
+
export type { Computed, ReadSignal, Signal } from './signals'
|
|
84
|
+
export { batch, computed, effect, signal, untracked } from './signals'
|
|
85
|
+
// Timing
|
|
86
|
+
export { debounced, throttled } from './timing'
|
|
87
|
+
|
|
88
|
+
// Utilities
|
|
89
|
+
export { isAbortError } from './utils'
|