Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actions/unit-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ runs:
run: |
npm run test:unit
shell: bash
- name: Run type tests
run: |
npm run test:types
shell: bash
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
],
"scripts": {
"prepublishOnly": "npm run build",
"test": "npm run test:lint && npm run test:unit && npm run test:functional",
"test": "npm run test:lint && npm run test:unit && npm run test:types && npm run test:functional",
"test:unit": "nyc --reporter=text-summary --reporter=lcov mocha",
"test:types": "tsc -p test/types/tsconfig.json",
"test:functional": "cucumber-js --exit --fail-fast -c cucumber.config.cjs",
"test:lint": "eslint . --fix",
"build": "tsc --build tsconfig.json && vite build",
Expand All @@ -42,6 +43,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"kuzzle-types": "^1.0.0-beta.1",
"ws": "8.18.3"
},
"devDependencies": {
Expand Down
39 changes: 3 additions & 36 deletions src/types/ApiKey.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
/**
* ApiKey
*
* @see https://docs.kuzzle.io/core/2/guides/advanced/api-keys/
*/
export type ApiKey = {
/**
* ApiKey unique ID
*/
_id: string;
/**
* ApiKey content
*/
_source: {
/**
* User kuid
*/
userId: string;
/**
* Expiration date in Epoch-millis format (-1 if the token never expires)
*/
expiresAt: number;
/**
* Original TTL in ms
*/
ttl: number;
/**
* API key description
*/
description: string;
/**
* Authentication token associated with this API key
*/
token: string;
};
};
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). Kept so that imports of this path still work.
export type { ApiKey } from "kuzzle-types";
13 changes: 3 additions & 10 deletions src/types/ArgsDefault.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/**
* Generic API action arguments
*/
export interface ArgsDefault {
queuable?: boolean;

timeout?: number;

[name: string]: any;
}
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). Kept so that imports of this path still work.
export type { ArgsDefault } from "kuzzle-types";
12 changes: 3 additions & 9 deletions src/types/BaseRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { JSONObject } from "./JSONObject";

export interface BaseRequest extends JSONObject {
controller: string;

action: string;

body?: JSONObject;
}
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). Kept so that imports of this path still work.
export type { BaseRequest } from "kuzzle-types";
24 changes: 5 additions & 19 deletions src/types/Document.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { JSONObject } from "./JSONObject";
import { KDocumentKuzzleInfo } from "./KDocument";
import type { DocumentContent, JSONObject } from "kuzzle-types";

/**
* Kuzzle metadata
*
* @deprecated Use "KDocumentKuzzleInfo"
*/
export interface DocumentMetadata {
_kuzzle_info?: Partial<KDocumentKuzzleInfo>;
}

/**
* Represents the `_source` property of the document
*
* @deprecated Create an interface extending "KDocumentContent"
*/
export interface DocumentContent extends DocumentMetadata {
[key: string]: JSONObject | any;
}
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). `Document` stays here: it is a class, a runtime
// value, which the types-only kuzzle-types declares as an interface.
export type { DocumentContent, DocumentMetadata } from "kuzzle-types";

/**
* Kuzzle document
Expand Down
42 changes: 3 additions & 39 deletions src/types/HttpRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
/**
* HTTP routes definition format
*
* @see https://docs.kuzzle.io/core/2/guides/develop-on-kuzzle/api-controllers/#http-routes
*
* @example
* {
* <controller>: {
* <action>: { verb: <verb>, url: <url> }
* }
* }
*
* {
* 'my-plugin/my-controller': {
* action: { verb: 'GET', url: '/some/url' },
* action2: { verb: 'GET', url: '/some/url/with/:parameter' }
* }
* }
*/
export type HttpRoutes = {
/**
* Controller name
*/
[controller: string]: {
/**
* Action name
*/
[action: string]: {
/**
* HTTP verb
*/
verb: string;
/**
* URL
*/
url: string;
};
};
};
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). Kept so that imports of this path still work.
export type { HttpRoutes } from "kuzzle-types";
7 changes: 3 additions & 4 deletions src/types/JSONObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/**
* An interface representing an object with string key and any value
*/
export type JSONObject = Record<PropertyKey, any>;
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). Kept so that imports of this path still work.
export type { JSONObject } from "kuzzle-types";
92 changes: 9 additions & 83 deletions src/types/KDocument.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,9 @@
import { JSONObject } from "./JSONObject";

/**
* Represents Kuzzle Metadata.
*/
export interface KDocumentKuzzleInfo {
/**
* Kuid of the user who created the document
*/
author: string;

/**
* Creation date in micro-timestamp
*/
createdAt: number;

/**
* Kuid of the user who last updated the document
*/
updater: string | null;

/**
* Update date in micro-timestamp
*/
updatedAt: number | null;
}

/**
* Base interface for a Kuzzle document content
*/
export interface KDocumentContent {
_kuzzle_info?: KDocumentKuzzleInfo;
}

/**
* Generic kuzzle document content
*/
export interface KDocumentContentGeneric extends KDocumentContent, JSONObject {}

/**
* Represents a Kuzzle document
*
* Type argument represents the document content in the "_source" property
*/
export interface KDocument<TKDocumentContent extends KDocumentContent> {
/**
* Unique ID
*/
_id: string;

/**
* Content
*/
_source: TKDocumentContent;

created?: boolean;

_version?: number;
}

/**
* Represents a Kuzzle document retrieved from search
*/
export interface KHit<
TKDocumentContent extends KDocumentContent,
> extends KDocument<TKDocumentContent> {
/**
* Elasticsearch relevance score
*/
_score: number;

/**
* Document index
* Present only in the case of a multi search
*/
index?: string;

/**
* Document collection
* Present only in the case of a multi search
*/
collection?: string;
}
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). Kept so that imports of this path still work.
export type {
KDocumentKuzzleInfo,
KDocumentContent,
KDocumentContentGeneric,
KDocument,
KHit,
} from "kuzzle-types";
68 changes: 3 additions & 65 deletions src/types/Mappings.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,3 @@
import { JSONObject } from "./JSONObject";

type PropertyObject = {
properties?: MappingsProperties;
};

type PropertyDynamic = {
/**
* Dynamic mapping policy
*
* @see https://docs.kuzzle.io/core/2/guides/main-concepts/data-storage/#mappings-dynamic-policy
*/
dynamic?: "true" | "false" | "strict";
};

type PropertyType = {
[name: string]: { type?: string } | PropertyObject | JSONObject;
};

export type MappingsProperties =
| PropertyObject
| PropertyDynamic
| PropertyType;

/**
* Collection mappings definition
*
* @see https://docs.kuzzle.io/core/2/guides/main-concepts/data-storage/#collection-mappings
*
* @example
* ```
* {
* properties: {
* name: { type: 'keyword' },
* address: {
* properties: {
* zipcode: { type: 'integer' }
* }
* }
* }
* }
* ```
*/
export type CollectionMappings = {
/**
* Collection metadata
*
* @see https://docs.kuzzle.io/core/2/guides/main-concepts/data-storage/#mappings-metadata
*/
_meta?: JSONObject;

/**
* Properties types definition
*
* @see https://docs.kuzzle.io/core/2/guides/main-concepts/data-storage/#mappings-properties
*/
properties?: MappingsProperties;

/**
* Dynamic mapping policy
*
* @see https://docs.kuzzle.io/core/2/guides/main-concepts/data-storage/#mappings-dynamic-polic
*/
dynamic?: "true" | "false" | "strict";
};
// Moved to kuzzle-types, the API contract shared by kuzzle and kuzzle-sdk
// (Kuzzle ADR-0002 step 03). Kept so that imports of this path still work.
export type { MappingsProperties, CollectionMappings } from "kuzzle-types";
Loading
Loading