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
8 changes: 8 additions & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This changelog covers all three packages, as they are (for now) updated as a who

### @tomic/lib

- [#840](https://github.com/atomicdata-dev/atomic-server/issues/840) Added `store.search()`.
- Deprecated `resource.getSubject()` in favor of `resource.subject`.
- Deprecated `store.getResouceAsync()` in favor of `store.getResource()`.
- Deprecated `resource.pushPropval()` in favor of `resource.push()`.
Expand All @@ -34,6 +35,13 @@ This changelog covers all three packages, as they are (for now) updated as a who
- `resource.removeClasses()`
- `resource.addClasses()`

### @tomic/cli

- [#837](https://github.com/atomicdata-dev/atomic-server/issues/837) Fix timestamp is mapped to string instead of number.
- [#831](https://github.com/atomicdata-dev/atomic-server/issues/831) Give clear error when trying to generate types from a non ontology resource
- [#830](https://github.com/atomicdata-dev/atomic-server/issues/830) Create output folder if it doesn't exist
- Use type import in generated files.

## v0.37.0

### Atomic Browser
Expand Down
2 changes: 1 addition & 1 deletion browser/cli/src/DatatypeToTSTypeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const DatatypeToTSTypeMap = {
[Datatype.RESOURCEARRAY]: 'string[]',
[Datatype.BOOLEAN]: 'boolean',
[Datatype.DATE]: 'string',
[Datatype.TIMESTAMP]: 'string',
[Datatype.TIMESTAMP]: 'number',
[Datatype.INTEGER]: 'number',
[Datatype.FLOAT]: 'number',
[Datatype.STRING]: 'string',
Expand Down
26 changes: 20 additions & 6 deletions browser/cli/src/commands/ontologies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ import { atomicConfig } from '../config.js';
import { generateIndex } from '../generateIndex.js';
import { PropertyRecord } from '../PropertyRecord.js';
import { generateExternals } from '../generateExternals.js';
import { validateOntologies } from '../validateOntologies.js';

export const ontologiesCommand = async (_args: string[]) => {
const propertyRecord = new PropertyRecord();

console.log(
chalk.blue(
`Found ${chalk.red(
Object.keys(atomicConfig.ontologies).length,
)} ontologies`,
),
chalk.blue(`Found ${chalk.red(atomicConfig.ontologies.length)} ontologies`),
);

for (const subject of Object.values(atomicConfig.ontologies)) {
const [valid, report] = await validateOntologies(atomicConfig.ontologies);

if (!valid) {
console.log(chalk.red('Could not generate ontologies'));
console.log(report);

return;
}

checkOrCreateFolder(atomicConfig.outputFolder);

for (const subject of atomicConfig.ontologies) {
await write(await generateOntology(subject, propertyRecord));
}

Expand Down Expand Up @@ -73,3 +81,9 @@ const write = async ({

console.log(chalk.blue('Wrote to'), chalk.cyan(filePath));
};

const checkOrCreateFolder = (relativePath: string): void => {
const fullPath = path.join(process.cwd(), relativePath);

fs.mkdirSync(fullPath, { recursive: true });
};
3 changes: 1 addition & 2 deletions browser/cli/src/generateOntology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { generateBaseObject } from './generateBaseObject.js';
import { generateClasses } from './generateClasses.js';
import { store } from './store.js';
import { camelCaseify } from './utils.js';
// TODO: Replace with actual project config file.
import { generatePropTypeMapping } from './generatePropTypeMapping.js';
import { generateSubjectToNameMapping } from './generateSubjectToNameMapping.js';
import { generateClassExports } from './generateClassExports.js';
Expand All @@ -26,7 +25,7 @@ const TEMPLATE = `
* For more info on how to use ontologies: https://github.com/atomicdata-dev/atomic-server/blob/develop/browser/cli/readme.md
* -------------------------------- */

import { BaseProps } from '${Inserts.MODULE_ALIAS}'
import type { BaseProps } from '${Inserts.MODULE_ALIAS}'

${Inserts.BASE_OBJECT}

Expand Down
29 changes: 29 additions & 0 deletions browser/cli/src/validateOntologies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { core } from '@tomic/lib';
import { store } from './store.js';
import chalk from 'chalk';

export const validateOntologies = async (
ontologies: string[],
): Promise<[valid: boolean, report: string]> => {
let isValid = true;
let report = '';

for (const subject of ontologies) {
try {
const resource = await store.getResourceAsync(subject);

if (!resource.hasClasses(core.classes.ontology)) {
isValid = false;
const isA = await store.getResourceAsync(resource.getClasses()[0]);
report += `Expected ${chalk.cyan(
resource.title,
)} to have class Ontology but found ${chalk.cyan(isA.title)}\n`;
}
} catch (e) {
isValid = false;
report += `Could not fetch ontology at ${subject}\n`;
}
}

return [isValid, report];
};
13 changes: 13 additions & 0 deletions browser/lib/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
commits,
collections,
JSONValue,
SearchOpts,
buildSearchSubject,
server,
} from './index.js';
import { authenticate, fetchWebSocket, startWebsocket } from './websockets.js';

Expand Down Expand Up @@ -232,6 +235,16 @@ export class Store {
return resource;
}

public async search(query: string, opts: SearchOpts = {}): Promise<string[]> {
const searchSubject = buildSearchSubject(this.serverUrl, query, opts);
const searchResource = await this.fetchResourceFromServer(searchSubject, {
noWebSocket: true,
});
const results = searchResource.get(server.properties.results) ?? [];

return results;
}

/** Checks if a subject is free to use */
public async checkSubjectTaken(subject: string): Promise<boolean> {
const r = this.resources.get(subject);
Expand Down
2 changes: 1 addition & 1 deletion browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"cli"
]
},
"packageManager": "pnpm@8.6.12",
"packageManager": "pnpm@8.15.2",
"dependencies": {
"eslint-plugin-import": "^2.26.0"
}
Expand Down
1 change: 0 additions & 1 deletion browser/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"module": "./dist/index.js",
"main-dev": "src/index.ts",
"name": "@tomic/svelte",
"packageManager": "pnpm@7.13.3",
"peerDependencies": {
"@tomic/lib": "workspace:*"
},
Expand Down
24 changes: 18 additions & 6 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# AtomicServer

- [AtomicServer](atomic-server.md)
- [When (not) to use it](atomicserver/when-to-use.md)
- [When (not) to use it](atomicserver/when-to-use.md))]
- [Installation](atomicserver/installation.md)
- [FAQ & troubleshooting](atomicserver/faq.md)
- [Getting started with the GUI](atomicserver/gui.md)
- [API](atomicserver/API.md)
- [Creating a JSON-AD file](create-json-ad.md)
Expand All @@ -30,9 +31,23 @@
- [Rust lib](rust-lib.md)
- [Rust CLI](rust-cli.md)

# Specification (core)
# Guides

- [Build a portfolio using Astro and Atomic Server](astro-guide/1-index.md)
- [Setup](astro-guide/2-setup.md)
- [Frontend setup](astro-guide/3-frontend-setup.md)
- [Basic data model](astro-guide/4-basic-data-model.md)
- [Creating homepage data](astro-guide/5-creating-homepage-data.md)
- [Generating types](astro-guide/6-generating-types.md)
- [Fetching data](astro-guide/7-fetching-data.md)
- [Using ResourceArray to display a list of projects](astro-guide/8-pojects.md)
- [Using Collections to build the blogs page](astro-guide/9-blogs.md)
- [Using the search API to build a search bar](astro-guide/10-search.md)

# Specification

- [Atomic Data Core](core/concepts.md)

- [What is Atomic Data?](core/concepts.md)
- [Serialization](core/serialization.md)
- [JSON-AD](core/json-ad.md)
- [Querying](core/querying.md)
Expand All @@ -42,8 +57,6 @@
- [Datatypes](schema/datatypes.md)
- [FAQ](schema/faq.md)

# Specification (extended)

- [Atomic Data Extended](extended.md)
- [Agents](agents.md)
- [Hierarchy and authorization](hierarchy.md)
Expand All @@ -70,7 +83,6 @@
- [Graph Databases](interoperability/graph-database.md)
- [Potential use cases](usecases/intro.md)
- [As a Headless CMS](usecases/headless-cms.md)
- [In a React project](usecases/react.md)
- [Personal Data Store](usecases/personal-data-store.md)
- [Artificial Intelligence](usecases/ai.md)
- [E-commerce & marketplaces](usecases/e-commerce.md)
Expand Down
1 change: 1 addition & 0 deletions docs/src/acknowledgements.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Authors:

- **Joep Meindertsma** ([joepio](https://github.com/joepio/) from [Ontola.io](https://ontola.io/))
- **Polle Pas** ([polleps](https://github.com/polleps/) from [Ontola.io](https://ontola.io/))

## Special thanks to:

Expand Down
16 changes: 16 additions & 0 deletions docs/src/astro-guide/1-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Creating a portfolio website using Astro and Atomic Server

Atomic Server is a great fit for a headless CMS because it works seamlessly on the server and client while providing a top-notch developer experience.
In this guide, we will build a portfolio site using [Astro](https://astro.build/) to serve and build our pages and use Atomic Data to hold our data.

Astro is a web framework for creating fast multi-page applications using web technology.
It plays very nicely with the `@tomic/lib` client library.

There are a few things that won't be covered in this guide like styling and CSS.
There will be very minimal use of CSS in this guide so we can focus on the technical parts of the website.
Feel free to spice it up and add some styling while following along though.

I will also not cover every little detail about Astro, only what is necessary to follow along with this guide.
If you're completely new to Astro consider skimming the [documentation](https://docs.astro.build/en/getting-started/) to see what it has to offer.

With all that out of the way let's start by setting up your atomic data server. If you already have a server running skip to [Creating the frontend](3-frontend-setup.md)
Loading