@blockprotocol/type-system
Advanced tools
Comparing version 0.0.3 to 0.0.4-20230124234232
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
@@ -101,2 +101,10 @@ let wasm; | ||
let stack_pointer = 32; | ||
function addBorrowedObject(obj) { | ||
if (stack_pointer == 1) throw new Error('out of js stack'); | ||
heap[--stack_pointer] = obj; | ||
return stack_pointer; | ||
} | ||
function dropObject(idx) { | ||
@@ -114,80 +122,2 @@ if (idx < 36) return; | ||
/** | ||
* @param {string} uri | ||
* @returns {any} | ||
*/ | ||
function validateBaseUri(uri) { | ||
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.validateBaseUri(ptr0, len0); | ||
return takeObject(ret); | ||
} | ||
/** | ||
* @param {string} uri | ||
* @returns {any} | ||
*/ | ||
function validateVersionedUri(uri) { | ||
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
const ret = wasm.validateVersionedUri(ptr0, len0); | ||
return takeObject(ret); | ||
} | ||
/** | ||
* @param {string} uri | ||
* @returns {string} | ||
*/ | ||
function extractBaseUri(uri) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.extractBaseUri(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
var r3 = getInt32Memory0()[retptr / 4 + 3]; | ||
var ptr1 = r0; | ||
var len1 = r1; | ||
if (r3) { | ||
ptr1 = 0; len1 = 0; | ||
throw takeObject(r2); | ||
} | ||
return getStringFromWasm0(ptr1, len1); | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
wasm.__wbindgen_free(ptr1, len1); | ||
} | ||
} | ||
/** | ||
* @param {string} uri | ||
* @returns {number} | ||
*/ | ||
function extractVersion(uri) { | ||
try { | ||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); | ||
const ptr0 = passStringToWasm0(uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.extractVersion(retptr, ptr0, len0); | ||
var r0 = getInt32Memory0()[retptr / 4 + 0]; | ||
var r1 = getInt32Memory0()[retptr / 4 + 1]; | ||
var r2 = getInt32Memory0()[retptr / 4 + 2]; | ||
if (r2) { | ||
throw takeObject(r1); | ||
} | ||
return r0 >>> 0; | ||
} finally { | ||
wasm.__wbindgen_add_to_stack_pointer(16); | ||
} | ||
} | ||
let stack_pointer = 32; | ||
function addBorrowedObject(obj) { | ||
if (stack_pointer == 1) throw new Error('out of js stack'); | ||
heap[--stack_pointer] = obj; | ||
return stack_pointer; | ||
} | ||
/** | ||
* @param {any} data_type_obj | ||
@@ -338,2 +268,121 @@ * @returns {any} | ||
/** | ||
* Checks if a given URL string is a valid base URL. | ||
* | ||
* @param {BaseUri} uri - The URL string. | ||
* @returns {(Result<BaseUri, ParseBaseUriError>)} - an Ok with an inner of the string as a | ||
* BaseUri if valid, or an Err with an inner ParseBaseUriError | ||
*/ | ||
const validateBaseUri = (uri) => { | ||
try { | ||
void new URL(uri); | ||
if (uri.endsWith("/")) { | ||
return { | ||
type: "Ok", | ||
inner: uri, | ||
}; | ||
} | ||
else { | ||
return { | ||
type: "Err", | ||
inner: { reason: "MissingTrailingSlash" }, | ||
}; | ||
} | ||
} | ||
catch (err) { | ||
return { | ||
type: "Err", | ||
inner: { reason: "UrlParseError", inner: JSON.stringify(err) }, | ||
}; | ||
} | ||
}; | ||
const versionedUriRegExp = /(.+\/)v\/(\d+)(.*)/; | ||
/** | ||
* Checks if a given URL string is a Block Protocol compliant Versioned URI. | ||
* | ||
* @param {string} uri - The URL string. | ||
* @returns {(Result<VersionedUri, ParseVersionedUriError>)} - an Ok with an inner of the string | ||
as | ||
* a VersionedUri if valid, or an Err with an inner ParseVersionedUriError | ||
*/ | ||
const validateVersionedUri = (uri) => { | ||
const groups = versionedUriRegExp.exec(uri); | ||
if (groups === null) { | ||
return { | ||
type: "Err", | ||
inner: { reason: "IncorrectFormatting" }, | ||
}; | ||
} | ||
else { | ||
const [_match, baseUri, version, trailingContent] = groups; | ||
if (trailingContent) { | ||
return { | ||
type: "Err", | ||
inner: { reason: "AdditionalEndContent" }, | ||
}; | ||
} | ||
if (!version) { | ||
return { | ||
type: "Err", | ||
inner: { reason: "MissingVersion" }, | ||
}; | ||
} | ||
if (!baseUri) { | ||
return { | ||
type: "Err", | ||
inner: { reason: "MissingBaseUri" }, | ||
}; | ||
} | ||
const validBaseUriResult = validateBaseUri(baseUri); | ||
if (validBaseUriResult.type === "Err") { | ||
return { | ||
type: "Err", | ||
inner: { reason: "InvalidBaseUri", inner: validBaseUriResult.inner }, | ||
}; | ||
} | ||
const versionNumber = Number(version); | ||
if (!Number.isInteger(versionNumber) || versionNumber < 0) { | ||
return { | ||
type: "Err", | ||
inner: { | ||
reason: "InvalidVersion", | ||
inner: `\`${version}\` is not a valid non-negative integer`, | ||
}, | ||
}; | ||
} | ||
return { type: "Ok", inner: uri }; | ||
} | ||
}; | ||
/** | ||
* Extracts the base URI from a Versioned URI. | ||
* | ||
* @param {VersionedUri} uri - The versioned URI. | ||
* @throws if the versioned URI is invalid. | ||
*/ | ||
const extractBaseUri = (uri) => { | ||
const groups = versionedUriRegExp.exec(uri); | ||
if (groups === null) { | ||
throw new Error(`Not a valid VersionedUri: ${uri}`); | ||
} | ||
const [_match, baseUri, _version] = groups; | ||
if (baseUri === undefined) { | ||
throw new Error(`Not a valid VersionedUri: ${uri}`); | ||
} | ||
return baseUri; | ||
}; | ||
/** | ||
* Extracts the version from a Versioned URI. | ||
* | ||
* @param {VersionedUri} uri - The versioned URI. | ||
* @throws if the versioned URI is invalid. | ||
*/ | ||
const extractVersion = (uri) => { | ||
const groups = versionedUriRegExp.exec(uri); | ||
if (groups === null) { | ||
throw new Error(`Not a valid VersionedUri: ${uri}`); | ||
} | ||
const [_match, _baseUri, version] = groups; | ||
return Number(version); | ||
}; | ||
export { TypeSystemInitializer, extractBaseUri, extractVersion, initSync, validateBaseUri, validateDataType, validateEntityType, validatePropertyType, validateVersionedUri }; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
export * from "../wasm/type-system"; | ||
export { TypeSystemInitializer } from "./common"; | ||
export * from "./native"; |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export type VersionedUri = `${string}/v/${number}`; | ||
export type BaseUri = string; | ||
/** | ||
* Checks if a given URL string is a valid base URL. | ||
* | ||
* @param {BaseUri} uri - The URL string. | ||
* @returns {(Result.Ok|Result.Err<ParseBaseUriError>)} - an Ok with an inner of the string as a | ||
* BaseUri if valid, or an Err with an inner ParseBaseUriError | ||
*/ | ||
export function validateBaseUri(uri: string): Result<BaseUri, ParseBaseUriError>; | ||
/** | ||
* Checks if a given URL string is a Block Protocol compliant Versioned URI. | ||
* | ||
* @param {string} uri - The URL string. | ||
* @returns {(Result.Ok|Result.Err<ParseVersionedUriError>)} - an Ok with an inner of the string as | ||
* a VersionedUri if valid, or an Err with an inner ParseVersionedUriError | ||
*/ | ||
export function validateVersionedUri(uri: string): Result<VersionedUri, ParseVersionedUriError>; | ||
/** | ||
* Extracts the base URI from a Versioned URI. | ||
* | ||
* @param {VersionedUri} uri - The versioned URI. | ||
* @throws {ParseVersionedUriError} if the versioned URI is invalid. | ||
*/ | ||
export function extractBaseUri(uri: VersionedUri): BaseUri; | ||
/** | ||
* Extracts the version from a Versioned URI. | ||
* | ||
* @param {VersionedUri} uri - The versioned URI. | ||
* @throws {ParseVersionedUriError} if the versioned URI is invalid. | ||
*/ | ||
export function extractVersion(uri: VersionedUri): number; | ||
export interface DataTypeReference { | ||
@@ -53,4 +11,2 @@ $ref: VersionedUri; | ||
export type BaseUri = string; | ||
export type ParseVersionedUriError = { reason: "IncorrectFormatting" } | { reason: "MissingBaseUri" } | { reason: "MissingVersion" } | { reason: "InvalidVersion"; inner: string } | { reason: "AdditionalEndContent" } | { reason: "InvalidBaseUri"; inner: ParseBaseUriError } | { reason: "InvalidJson"; inner: string }; | ||
@@ -72,15 +28,2 @@ | ||
export interface OneOf<T> { | ||
oneOf: [T, ...T[]]; | ||
} | ||
export type ValueOrArray<T> = T | Array<T>; | ||
export interface Array<T> { | ||
type: 'array'; | ||
items: T; | ||
minItems?: number; | ||
maxItems?: number; | ||
} | ||
export interface PropertyType extends OneOf<PropertyValues> { | ||
@@ -99,41 +42,28 @@ kind: 'propertyType'; | ||
export type ValidationError = { type: "MissingRequiredProperty"; inner: BaseUri } | { type: "BaseUriMismatch"; inner: { base_uri: BaseUri; versioned_uri: VersionedUri } } | { type: "MissingRequiredLink"; inner: VersionedUri } | { type: "MismatchedPropertyCount"; inner: { actual: number; expected: number } } | { type: "EmptyOneOf" }; | ||
export type ParseOneOfError = { reason: "EntityTypeReferenceError"; inner: ParseVersionedUriError } | { reason: "PropertyValuesError"; inner: ParsePropertyTypeError } | { reason: "ValidationError"; inner: ValidationError }; | ||
export type ParseEntityTypeError = { reason: "InvalidPropertyTypeObject"; inner: ParsePropertyTypeObjectError } | { reason: "InvalidAllOf"; inner: ParseAllOfError } | { reason: "InvalidLinks"; inner: ParseLinksError } | { reason: "InvalidDefaultKey"; inner: ParseBaseUriError } | { reason: "InvalidExamplesKey"; inner: ParseBaseUriError } | { reason: "InvalidVersionedUri"; inner: ParseVersionedUriError } | { reason: "InvalidJson"; inner: string }; | ||
export type Result<T, E> = { type: "Ok"; inner: T } | { type: "Err"; inner: E }; | ||
export type ParsePropertyTypeObjectError = { reason: "InvalidPropertyTypeReference"; inner: ParseVersionedUriError } | { reason: "InvalidArray"; inner: ParsePropertyTypeReferenceArrayError } | { reason: "InvalidPropertyKey"; inner: ParseBaseUriError } | { reason: "InvalidRequiredKey"; inner: ParseBaseUriError } | { reason: "ValidationError"; inner: ValidationError } | { reason: "InvalidJson"; inner: string }; | ||
export interface OneOf<T> { | ||
oneOf: [T, ...T[]]; | ||
} | ||
export type ParseAllOfError = { reason: "EntityTypeReferenceError"; inner: ParseVersionedUriError }; | ||
export type ValueOrArray<T> = T | Array<T>; | ||
export type ParsePropertyTypeError = { reason: "InvalidVersionedUri"; inner: ParseVersionedUriError } | { reason: "InvalidDataTypeReference"; inner: ParseVersionedUriError } | { reason: "InvalidPropertyTypeObject"; inner: ParsePropertyTypeObjectError } | { reason: "InvalidOneOf"; inner: ParseOneOfError } | { reason: "InvalidArrayItems"; inner: ParseOneOfArrayError } | { reason: "InvalidJson"; inner: string }; | ||
export interface Links { | ||
links?: Record<VersionedUri, MaybeOrderedArray<MaybeOneOfEntityTypeReference>>; | ||
requiredLinks?: VersionedUri[]; | ||
export interface Array<T> { | ||
type: 'array'; | ||
items: T; | ||
minItems?: number; | ||
maxItems?: number; | ||
} | ||
export interface MaybeOrderedArray<T> extends Array<T> { | ||
ordered: boolean; | ||
} | ||
export type ValidationError = { type: "MissingRequiredProperty"; inner: BaseUri } | { type: "BaseUriMismatch"; inner: { base_uri: BaseUri; versioned_uri: VersionedUri } } | { type: "MissingRequiredLink"; inner: VersionedUri } | { type: "MismatchedPropertyCount"; inner: { actual: number; expected: number } } | { type: "EmptyOneOf" }; | ||
export interface EntityTypeReference { | ||
$ref: VersionedUri; | ||
} | ||
export type ParseOneOfError = { reason: "EntityTypeReferenceError"; inner: ParseVersionedUriError } | { reason: "PropertyValuesError"; inner: ParsePropertyTypeError } | { reason: "ValidationError"; inner: ValidationError }; | ||
export interface EntityType extends AllOf<EntityTypeReference>, Object<ValueOrArray<PropertyTypeReference>>, Links { | ||
kind: 'entityType'; | ||
$id: VersionedUri; | ||
title: string; | ||
description?: string; | ||
default?: Record<BaseUri, any>; | ||
examples?: Record<BaseUri, any>[]; | ||
} | ||
export type ParsePropertyTypeObjectError = { reason: "InvalidPropertyTypeReference"; inner: ParseVersionedUriError } | { reason: "InvalidArray"; inner: ParsePropertyTypeReferenceArrayError } | { reason: "InvalidPropertyKey"; inner: ParseBaseUriError } | { reason: "InvalidRequiredKey"; inner: ParseBaseUriError } | { reason: "ValidationError"; inner: ValidationError } | { reason: "InvalidJson"; inner: string }; | ||
export type ParseLinksError = { reason: "InvalidLinkKey"; inner: ParseVersionedUriError } | { reason: "InvalidArray"; inner: ParseEntityTypeReferenceArrayError } | { reason: "InvalidRequiredKey"; inner: ParseVersionedUriError } | { reason: "ValidationError"; inner: ValidationError } | { reason: "InvalidJson"; inner: string }; | ||
export type ParseAllOfError = { reason: "EntityTypeReferenceError"; inner: ParseVersionedUriError }; | ||
export type ParseEntityTypeError = { reason: "InvalidPropertyTypeObject"; inner: ParsePropertyTypeObjectError } | { reason: "InvalidAllOf"; inner: ParseAllOfError } | { reason: "InvalidLinks"; inner: ParseLinksError } | { reason: "InvalidDefaultKey"; inner: ParseBaseUriError } | { reason: "InvalidExamplesKey"; inner: ParseBaseUriError } | { reason: "InvalidVersionedUri"; inner: ParseVersionedUriError } | { reason: "InvalidJson"; inner: string }; | ||
/** | ||
@@ -168,2 +98,15 @@ * Checks if a given Data Type is correctly formed | ||
export type VersionedUri = `${string}/v/${number}`; | ||
export type ParsePropertyTypeError = { reason: "InvalidVersionedUri"; inner: ParseVersionedUriError } | { reason: "InvalidDataTypeReference"; inner: ParseVersionedUriError } | { reason: "InvalidPropertyTypeObject"; inner: ParsePropertyTypeObjectError } | { reason: "InvalidOneOf"; inner: ParseOneOfError } | { reason: "InvalidArrayItems"; inner: ParseOneOfArrayError } | { reason: "InvalidJson"; inner: string }; | ||
export interface Links { | ||
links?: Record<VersionedUri, MaybeOrderedArray<MaybeOneOfEntityTypeReference>>; | ||
requiredLinks?: VersionedUri[]; | ||
} | ||
export interface MaybeOrderedArray<T> extends Array<T> { | ||
ordered: boolean; | ||
} | ||
export interface AllOf<T> { | ||
@@ -173,4 +116,19 @@ allOf?: T[]; | ||
export interface EntityTypeReference { | ||
$ref: VersionedUri; | ||
} | ||
export interface EntityType extends AllOf<EntityTypeReference>, Object<ValueOrArray<PropertyTypeReference>>, Links { | ||
kind: 'entityType'; | ||
$id: VersionedUri; | ||
title: string; | ||
description?: string; | ||
default?: Record<BaseUri, any>; | ||
examples?: Record<BaseUri, any>[]; | ||
} | ||
export type MaybeOneOfEntityTypeReference = OneOf<EntityTypeReference> | {}; | ||
export type ParseLinksError = { reason: "InvalidLinkKey"; inner: ParseVersionedUriError } | { reason: "InvalidArray"; inner: ParseEntityTypeReferenceArrayError } | { reason: "InvalidRequiredKey"; inner: ParseVersionedUriError } | { reason: "ValidationError"; inner: ValidationError } | { reason: "InvalidJson"; inner: string }; | ||
export type ParseDataTypeError = { reason: "InvalidVersionedUri"; inner: ParseVersionedUriError } | { reason: "InvalidJson"; inner: string }; | ||
@@ -183,6 +141,2 @@ | ||
readonly memory: WebAssembly.Memory; | ||
readonly validateBaseUri: (a: number, b: number) => number; | ||
readonly validateVersionedUri: (a: number, b: number) => number; | ||
readonly extractBaseUri: (a: number, b: number, c: number) => void; | ||
readonly extractVersion: (a: number, b: number, c: number) => void; | ||
readonly validateDataType: (a: number) => number; | ||
@@ -193,4 +147,2 @@ readonly validateEntityType: (a: number) => number; | ||
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number; | ||
readonly __wbindgen_add_to_stack_pointer: (a: number) => number; | ||
readonly __wbindgen_free: (a: number, b: number) => void; | ||
} | ||
@@ -197,0 +149,0 @@ |
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function validateBaseUri(a: number, b: number): number; | ||
export function validateVersionedUri(a: number, b: number): number; | ||
export function extractBaseUri(a: number, b: number, c: number): void; | ||
export function extractVersion(a: number, b: number, c: number): void; | ||
export function validateDataType(a: number): number; | ||
@@ -13,3 +9,1 @@ export function validateEntityType(a: number): number; | ||
export function __wbindgen_realloc(a: number, b: number, c: number): number; | ||
export function __wbindgen_add_to_stack_pointer(a: number): number; | ||
export function __wbindgen_free(a: number, b: number): void; |
{ | ||
"name": "@blockprotocol/type-system", | ||
"version": "0.0.3", | ||
"version": "0.0.4-20230124234232", | ||
"description": "Definitions of types within the Block Protocol Type System", | ||
@@ -5,0 +5,0 @@ "homepage": "https://blockprotocol.org", |
# Block Protocol Type System | ||
An in-development package that provides Typescript typings and implementations for the Block Protocol Type-System. See the [RFC](https://github.com/blockprotocol/blockprotocol/blob/main/rfcs/text/0352-graph-type-system.md) for more details | ||
An in-development package that provides TypeScript typings and implementations for the Block Protocol Type-System. See the [RFC](https://github.com/blockprotocol/blockprotocol/blob/main/rfcs/text/0352-graph-type-system.md) for more details | ||
@@ -5,0 +5,0 @@ ## Development |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
36
25791
7149688