Skip to content

Commit

Permalink
Add types for GridLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
tajakobsen committed Jun 27, 2022
1 parent 86d2c6d commit 6cf3652
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-unused-vars": "off"
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-interface": "off"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ declare const __non_webpack_require__: <K extends keyof LibMap | string = string
* [ExportLibrary](./src/export.ts)
* [FreeMarkerLibrary](./src/freemarker.ts)
* [GraphQLLibrary](./src/graphql.ts)
* [GridLibrary](./src/grid.ts)
* [GuillotineLibrary](./src/guillotine.ts)
* [HttpLibrary](./src/http.ts)
* [I18nLibrary](./src/i18n.ts)
Expand Down
206 changes: 103 additions & 103 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "enonic-types",
"sideEffects": false,
"version": "0.4.9",
"version": "0.4.10",
"description": "TypeScript types for Enonic XP",
"typings": "index.d.ts",
"scripts": {
Expand All @@ -26,15 +26,15 @@
},
"homepage": "https://github.com/ItemConsulting/enonic-types#readme",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"copyfiles": "^2.4.1",
"eslint": "^8.17.0",
"eslint": "^8.18.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"json-schema-to-typescript": "^10.1.5",
"prettier": "^2.7.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.7.3"
"typescript": "^4.7.4"
}
}
79 changes: 79 additions & 0 deletions src/grid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
declare module "*/lib/xp/grid" {
namespace gridLib {
export type GridMap = Record<string, any>;

/**
* @since 7.10.0
*/
interface GridLibrary {
/**
* Returns an instance of Shared Memory (Shared Map) by the specified map identifier.
*/
getMap<Map extends GridMap>(mapId: string): SharedMemory<Map>;
}

export interface SharedMemory<Map extends GridMap> {
/**
* Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
*/
get<Key extends keyof Map>(key: Key): Map[Key] | null;

/**
* Puts an entry into this map with a given time to live (TTL).
* If value is null, the existing entry will be removed.
*/
set<Key extends keyof Map>(params: SetParams<Map, Key>): void;

/**
* Removes the mapping for the key from this map if it is present.
*/
delete(key: keyof Map): void;

/**
* Attempts to compute a mapping for the specified key and its current mapped value.
*/
modify<Key extends keyof Map>(params: ModifyParams<Map, Key>): void;
}

export interface SetParams<Map extends GridMap, Key extends keyof Map> {
/**
* Key of the entry
*/
key: Key;

/**
* Value of the entry
*/
value: Map[Key];

/**
* Maximum time to live in seconds for this entry to stay in the map. (0 means infinite, negative means map config
* default or infinite if map config is not available)
*/
ttlSeconds?: number;
}

interface ModifyParams<Map extends GridMap, Key extends keyof Map> {
/**
* Key of the entry
*/
key: Key;

/**
* Mapping function that accepts the existing mapped value (or null, if there is no associated mapping).
* The returned value replaces the existing mapped value for the specified key.
* If returned value is null then the value is removed from the map
*/
func: (value: Map[Key]) => Map[Key];

/**
* Maximum time to live in seconds for this entry to stay in the map.
* (0 means infinite, negative means map config default or infinite if map config is not available)
*/
ttlSeconds?: number;
}
}

const gridLib: gridLib.GridLibrary;
export = gridLib;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/// <reference path="export.ts" />
/// <reference path="freemarker.ts" />
/// <reference path="graphql.ts" />
/// <reference path="grid.ts" />
/// <reference path="guillotine.ts" />
/// <reference path="http.ts" />
/// <reference path="i18n.ts" />
Expand Down
1 change: 1 addition & 0 deletions src/libs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface EnonicLibraryMap {
"/lib/tineikt/freemarker": typeof import("/lib/tineikt/freemarker");
"/lib/graphql": typeof import("/lib/graphql");
"/lib/graphql-playground": typeof import("/lib/graphql-playground");
"/lib/xp/grid": typeof import("/lib/xp/grid");
"/lib/guillotine": typeof import("/lib/guillotine");
"/lib/http-client": typeof import("/lib/http-client");
"/lib/xp/i18n": typeof import("/lib/xp/i18n");
Expand Down

0 comments on commit 6cf3652

Please sign in to comment.