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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ node_modules/
tests/package-lock.json
javascript/tsconfig.tsbuildinfo
javascript/.eslintcache
javascript/coverage/
17 changes: 0 additions & 17 deletions javascript/babel.config.cjs

This file was deleted.

27 changes: 3 additions & 24 deletions javascript/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,10 @@
* Distributed under the terms of the Modified BSD License.
*/

const path = require('path');
const esModules = ['lib0', 'y-protocols', 'y-websocket', 'yjs'].join('|');

module.exports = {
preset: 'ts-jest/presets/js-with-babel',
testTimeout: 10000,
testPathIgnorePatterns: ['/lib/', '/node_modules/'],
moduleFileExtensions: [
'ts',
'tsx',
'js',
'jsx',
'json',
'node',
'mjs',
'cjs'
],
transformIgnorePatterns: [`/node_modules/(?!${esModules}).+`],
reporters: ['default'],
coverageReporters: ['json', 'lcov', 'text', 'html'],
coverageDirectory: path.join(__dirname, 'coverage'),
testRegex: '/test/.*.spec.ts[x]?$',
globals: {
'ts-jest': {
tsconfig: `./tsconfig.test.json`
}
}
testEnvironment: 'node',
testRegex: 'lib/test/.*.spec.js[x]?$',

};
26 changes: 11 additions & 15 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,17 @@
"yjs": "^13.5.40"
},
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@types/jest": "^26.0.10",
"@typescript-eslint/eslint-plugin": "~5.28.0",
"@typescript-eslint/parser": "~5.28.0",
"eslint": "~8.17.0",
"eslint-config-prettier": "~8.5.0",
"eslint-plugin-jest": "~26.5.3",
"eslint-plugin-prettier": "~4.0.0",
"eslint-plugin-react": "~7.29.4",
"jest": "^26.4.2",
"prettier": "~2.6.0",
"rimraf": "~3.0.0",
"ts-jest": "^26.3.0",
"typescript": "~4.7.3"
"@types/jest": "^29.0.0",
"@typescript-eslint/eslint-plugin": "^5.36.0",
"@typescript-eslint/parser": "^5.36.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^27.0.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^29.0.0",
"prettier": "^2.6.0",
"rimraf": "^3.0.0",
"typescript": "^4.8.0"
},
"publishConfig": {
"access": "public"
Expand Down
57 changes: 34 additions & 23 deletions javascript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,34 @@ export interface ISharedNotebook extends ISharedDocument {
deleteMetadata(key: string): void;

/**
* Returns some metadata associated with the notebook.
* Returns all metadata associated with the notebook.
*
* If no `key` is provided, it will return all metadata.
* Else it will return the value for that key.
* @returns Notebook's metadata.
*/
getMetadata(): nbformat.INotebookMetadata;

/**
* Returns a metadata associated with the notebook.
*
* @param key Key to get from the metadata
* @returns Notebook's metadata.
*/
getMetadata(key?: string): nbformat.INotebookMetadata;
getMetadata(key: string): PartialJSONValue | undefined;

/**
* Sets some metadata associated with the notebook.
* Sets all metadata associated with the notebook.
*
* If only one argument is provided, it will override all notebook metadata.
* Otherwise a single key will be set to a new value.
* @param metadata All Notebook's metadata.
*/
setMetadata(metadata: nbformat.INotebookMetadata): void;

/**
* Sets a metadata associated with the notebook.
*
* @param metadata All Notebook's metadata or the key to set.
* @param metadata The key to set.
* @param value New metadata value
*/
setMetadata(
metadata: nbformat.INotebookMetadata | string,
value?: PartialJSONValue
): void;
setMetadata(metadata: string, value: PartialJSONValue): void;

/**
* Updates the metadata associated with the notebook.
Expand Down Expand Up @@ -427,28 +432,34 @@ export interface ISharedBaseCell<
deleteMetadata(key: string): void;

/**
* Returns some metadata associated with the cell.
* Returns all metadata associated with the cell.
*
* If a `key` is provided, returns the metadata value.
* Otherwise returns all metadata
* @returns Cell's metadata.
*/
getMetadata(): Partial<Metadata>;

/**
* Returns a metadata associated with the cell.
*
* @param key Metadata key to get
* @returns Cell's metadata.
*/
getMetadata(key?: string): Partial<Metadata>;
getMetadata(key: string): PartialJSONValue | undefined;

/**
* Sets some cell metadata.
*
* If only one argument is provided, it will override all cell metadata.
* Otherwise a single key will be set to a new value.
* @param metadata Cell's metadata.
*/
setMetadata(metadata: Partial<Metadata>): void;

/**
* Sets a cell metadata.
*
* @param metadata Cell's metadata or key.
* @param metadata Cell's metadata key.
* @param value Metadata value
*/
setMetadata(
metadata: Partial<Metadata> | string,
value?: PartialJSONValue
): void;
setMetadata(metadata: string, value: PartialJSONValue): void;

/**
* Serialize the model to JSON.
Expand Down
8 changes: 4 additions & 4 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
|----------------------------------------------------------------------------*/
/**
* @packageDocumentation
* @module shared-models
* @module ydoc
*/

export * from './api';
export * from './ymodels';
export * from './utils';
export * from './api.js';
export * from './ymodels.js';
export * from './utils.js';
2 changes: 1 addition & 1 deletion javascript/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
|----------------------------------------------------------------------------*/

import * as Y from 'yjs';
import * as models from './api';
import * as models from './api.js';

export function convertYMapEventToMapChange(
event: Y.YMapEvent<any>
Expand Down
22 changes: 15 additions & 7 deletions javascript/src/ymodels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type {
NotebookChange,
SharedCell,
StateChange
} from './api';
} from './api.js';

/**
* Abstract interface to define Shared Models that can be bound to a text editor using any existing
Expand Down Expand Up @@ -709,12 +709,14 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
}

/**
* Returns the metadata associated with the cell.
* Returns all or a single metadata associated with the cell.
*
* @param key
* @returns Cell metadata.
* @param key The metadata key
* @returns cell's metadata.
*/
getMetadata(key?: string): Partial<Metadata> {
getMetadata(): Partial<Metadata>;
getMetadata(key: string): PartialJSONValue | undefined;
getMetadata(key?: string): Partial<Metadata> | PartialJSONValue | undefined {
// Transiently the metadata can be missing - like during destruction
const metadata = this.ymodel.get('metadata') ?? {};

Expand All @@ -729,14 +731,16 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
}

/**
* Sets some cell metadata.
* Sets all or a single cell metadata.
*
* If only one argument is provided, it will override all cell metadata.
* Otherwise a single key will be set to a new value.
*
* @param metadata Cell's metadata or key.
* @param metadata Cell's metadata key or cell's metadata.
* @param value Metadata value
*/
setMetadata(metadata: Partial<Metadata>): void;
setMetadata(metadata: string, value: PartialJSONValue): void;
setMetadata(
metadata: Partial<Metadata> | string,
value?: PartialJSONValue
Expand Down Expand Up @@ -1467,6 +1471,8 @@ export class YNotebook
* @param key Key to get from the metadata
* @returns Notebook's metadata.
*/
getMetadata(): nbformat.INotebookMetadata;
getMetadata(key: string): PartialJSONValue | undefined;
getMetadata(key?: string): nbformat.INotebookMetadata {
const meta = this.ymeta.get('metadata') ?? {};

Expand All @@ -1489,6 +1495,8 @@ export class YNotebook
* @param metadata All Notebook's metadata or the key to set.
* @param value New metadata value
*/
setMetadata(metadata: nbformat.INotebookMetadata): void;
setMetadata(metadata: string, value: PartialJSONValue): void;
setMetadata(
metadata: nbformat.INotebookMetadata | string,
value?: PartialJSONValue
Expand Down
Loading