Commit 5ae01d56 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Initial import

parents
\.idea
^build$
^dist$
\.egg-info$
^.tox$
^.cache$
\.pyc$
\.pyo$
\.bak$
\.old$
\~$
\#.*?\#$
\.swp$
^doc/book/en/apidoc$
\.old$
\.pybuild
cubicweb/server/test/data/slapd.conf
debian/python-cubicweb
debian/*.log
debian/*.substvars
debian/cubicweb-doc
debian/cubicweb
debian/files
syntax: regexp
.*/data.*/database/.*
.*/data/ldapdb/.*
.*/data/uicache/
.*/data/libpython/cubicweb_.*/i18n/.*\.po
^doc/html/
^doc/doctrees/
^doc/book/en/devweb/js_api/
^doc/_build
^doc/js_api/
test-results.xml
include *.py
include */*.py
recursive-include cubicweb_tsgen *.py
recursive-include cubicweb_tsgen/data *.gif *.png *.ico *.css *.js
recursive-include cubicweb_tsgen/i18n *.po
recursive-include cubicweb_tsgen/wdoc *
recursive-include test/data bootstrap_cubes *.py
include *.ini
recursive-include debian changelog compat control copyright rules
include cubicweb-tsgen.spec
===================
cubicweb-tsgen
===================
cubicweb-tsgen provides a cubicweb-ctl command in order to generate the Typescript interfaces for a YAMS schema.
Basic use in Python
-------------------
.. highlight:: bash
cubicweb-ctl tsgen myinstance
# for el5, force use of python2.6
%if 0%{?el5}
%define python python26
%define __python /usr/bin/python2.6
%else
%define python python
%define __python /usr/bin/python
%endif
%{!?_python_sitelib: %define _python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
Name: cubicweb-tsgen
Version: 0.1.0
Release: logilab.1%{?dist}
Summary: Typescript interface generator
Group: Applications/Internet
License: LGPL
Source0: cubicweb-tsgen-%{version}.tar.gz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildRequires: %{python} %{python}-setuptools
Requires: cubicweb >= 3.27.0.dev0
Requires: %{python}-six >= 1.4.0
%description
Typescript interface generator
%prep
%setup -q -n cubicweb-tsgen-%{version}
%if 0%{?el5}
# change the python version in shebangs
find . -name '*.py' -type f -print0 | xargs -0 sed -i '1,3s;^#!.*python.*$;#! /usr/bin/python2.6;'
%endif
%install
%{__python} setup.py --quiet install --no-compile --prefix=%{_prefix} --root="$RPM_BUILD_ROOT"
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-, root, root)
%{_python_sitelib}/*
# copyright 2003-2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""Generation of Typescript interfaces for a YAMS schema"""
import codecs
from cubicweb import cwctl
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
_PRIMITIVES = {
"String": "string",
"Password": "string",
"Int": "number",
"Float": "number",
"Boolean": "boolean",
"Time": "string",
"Date": "string",
"Datetime": "string",
"TZTime": "string",
"TZDatetime": "string",
"Bytes": "string",
"BigInt": "string",
"Decimal": "string",
"Interval": "string",
"Jsonb": "any"
}
class TsSchemaGenerator:
"""
Generator of Typescript interfaces for a YAMS schema
"""
def __init__(self, schema):
"""
Initializes this generator
:param schema: The input YAMS schema
"""
self.schema = schema
self.errors = []
self._slices = []
def _print(self, text):
"""
Prints a piece of text to the output
:param text: The piece of text
:return: Nothing
"""
self._slices.append(text)
def _handle_attribute(self, entity, relation):
"""
Handles an attribute for a entity type
:param entity: The type of entity
:param relation: The attribute
:return: Nothing
"""
if relation.description is not None and len(relation.description) > 0:
self._print(" /**\n")
self._print(" * %s\n" % relation.description)
self._print(" */\n")
name = relation.type
field_type = relation.objects(entity)[0].type
if field_type in _PRIMITIVES:
field_type = _PRIMITIVES[field_type]
else:
field_type = "string"
self._print(" %s: %s;\n" % (name, field_type))
def _handle_relation_subject(self, entity, relation):
"""
Handles a relation for a entity type (when the entity is the subject)
:param entity: The type of entity
:param relation: The relation
:return: Nothing
"""
objects = relation.objects(entity.type)
for object_type in objects:
if relation.description is not None and len(relation.description) > 0:
self._print(" /**\n")
self._print(" * %s\n" % relation.description)
self._print(" */\n")
name = relation.type
self._print(" %s_%s_%s: number[];\n" % (name, entity.type, object_type.type))
def _handle_relation_object(self, entity, relation):
"""
Handles a relation for a entity type (when the entity is the object)
:param entity: The type of entity
:param relation: The relation
:return: Nothing
"""
subjects = relation.subjects(entity.type)
for subject in subjects:
if relation.description is not None and len(relation.description) > 0:
self._print(" /**\n")
self._print(" * %s\n" % relation.description)
self._print(" */\n")
name = relation.type
self._print(" %s_%s_%s: number[];\n" % (name, subject.type, entity.type))
def _handle_entity_type(self, entity):
"""
Handles a type of entity
:param entity: The type of entity
:return: Nothing
"""
if entity.description is not None and len(entity.description) > 0:
self._print("/**\n")
self._print(" * %s\n" % entity.description)
self._print(" */\n")
self._print("export interface %s" % entity.type)
parent = entity.specializes()
if parent is not None:
self._print(" extends %s" % parent.type)
self._print(" {\n")
for relation in entity.subject_relations():
if relation.type == "eid":
self._handle_attribute(entity, relation)
elif relation.final:
self._handle_attribute(entity, relation)
else:
self._handle_relation_subject(entity, relation)
for relation in entity.object_relations():
self._handle_relation_object(entity, relation)
self._print("}\n\n")
def generate(self):
"""
Generates the Typescript interfaces
:return: The text for the Typescript interfaces
"""
entities = [entity for entity in self.schema.entities() if not entity.final]
entities.sort(key=lambda x: x.type)
for entity in entities:
self._handle_entity_type(entity)
return ''.join(self._slices)
class TsGenCommand(cwctl.InstanceCommand):
"""Generates the Typescript type interfaces for an instance
<instance>...
identifiers of the instances to consider. If no instance is
given, recompile for all registered instances.
"""
name = 'tsgen'
@staticmethod
def tsgen_instance(app_id):
"""
Generates the Typescript type interfaces for an instance
:param app_id: The identifier of the instance
:return: Nothing
"""
config = cwcfg.config_for(app_id)
config.quick_start = True # notify this is not a regular start
schema = config.repository().schema
errors = TsGenCommand.tsgen_schema(schema)
if errors:
print('\n'.join(errors))
@staticmethod
def tsgen_schema(schema):
"""
Generates the Typescript type interfaces for a YAMS schema
:param schema: The schema
:return: The errors, if any
"""
generator = TsSchemaGenerator(schema)
content = generator.generate()
file = codecs.open("schema.ts", "w", "utf-8")
file.write(content)
file.close()
return generator.errors
cwctl.CWCTL.register(TsGenCommand)
# pylint: disable=W0622
"""cubicweb-tsgen application packaging information"""
modname = 'cubicweb_tsgen'
distname = 'cubicweb-tsgen'
numversion = (0, 1, 0)
version = '.'.join(str(num) for num in numversion)
license = 'LGPL'
author = 'LOGILAB S.A. (Paris, FRANCE)'
author_email = 'contact@logilab.fr'
description = 'Typescript interface generator'
web = 'http://www.cubicweb.org/project/%s' % distname
__depends__ = {
'cubicweb': '>= 3.26.4'
}
__recommends__ = {}
classifiers = [
'Environment :: Web Environment',
'Framework :: CubicWeb',
'Programming Language :: Python',
'Programming Language :: JavaScript',
]
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
cubicweb-graphql (0.1.0-1) UNRELEASED; urgency=low
* initial release
-- LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr> Thu, 21 Jun 2018 10:36:00 +0000
Source: cubicweb-tsgen
Section: web
Priority: optional
Maintainer: LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
Build-Depends:
debhelper (>= 7),
dh-python,
python (>= 2.6.5),
python-setuptools,
Standards-Version: 3.9.3
X-Python-Version: >= 2.6
Package: cubicweb-tsgen
Architecture: all
Depends:
python-cubicweb (>= 3.26.0),
python-six (>= 1.4.0),
${python:Depends},
${misc:Depends},
Description: Typescript interface generator
CubicWeb is a semantic web application framework.
.
Typescript interface generator
.
This package will install all the components you need to run an application
using the cubicweb-tsgen cube.
Upstream Author:
LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
Copyright:
Copyright (c) 2019 LOGILAB S.A. (Paris, FRANCE).
http://www.logilab.fr -- mailto:contact@logilab.fr
#!/usr/bin/make -f
%:
dh $@ --with python2
export interface Activity {
eid: number;
identity_Activity_Activity: number[];
/**
* internal entity uri
*/
cwuri: string;
actor_Activity_Person: number[];
actor_Activity_Naturalist: number[];
uri: string;
date: string;
source_Activity_Source: number[];
location_Activity_Location: number[];
cw_source_Activity_CWSource: number[];
/**
* core relation indicating owners of an entity. This relation implicitly put the owner into the owners group for the entity
*/
owned_by_Activity_CWUser: number[];
/**
* core relation indicating the types (including specialized types) of an entity
*/
is_instance_of_Activity_CWEType: number[];
/**
* core relation indicating the original creator of an entity
*/
created_by_Activity_CWUser: number[];
/**
* creation time of an entity
*/
creation_date: string;
/**
* core relation indicating the type of an entity
*/
is_Activity_CWEType: number[];
/**
* latest modification time of an entity
*/
modification_date: string;
identity_Activity_Activity: number[];
}
export interface Alignment {
eid: number;
identity_Alignment_Alignment: number[];
/**
* internal entity uri
*/
cwuri: string;
uri: string;
has_text: string;
source_Alignment_Source: number[];
confidence: number;
date: string;
cw_source_Alignment_CWSource: number[];
/**
* core relation indicating owners of an entity. This relation implicitly put the owner into the owners group for the entity
*/
owned_by_Alignment_CWUser: number[];
/**
* generic relation to specify that an external entity represent the same object as a local one: http://www.w3.org/TR/owl-ref/#sameAs-def
*/
same_as_Alignment_Location: number[];
/**
* generic relation to specify that an external entity represent the same object as a local one: http://www.w3.org/TR/owl-ref/#sameAs-def
*/
same_as_Alignment_Naturalist: number[];
/**
* core relation indicating the types (including specialized types) of an entity
*/
is_instance_of_Alignment_CWEType: number[];
/**
* core relation indicating the original creator of an entity
*/
created_by_Alignment_CWUser: number[];
/**
* creation time of an entity
*/
creation_date: string;
/**
* core relation indicating the type of an entity
*/
is_Alignment_CWEType: number[];
/**
* latest modification time of an entity
*/
modification_date: string;
identity_Alignment_Alignment: number[];
}
/**
* Authentication token
*/
export interface AuthToken {
eid: number;
identity_AuthToken_AuthToken: number[];
/**
* internal entity uri
*/
cwuri: string;
cw_source_AuthToken_CWSource: number[];
/**
* core relation indicating owners of an entity. This relation implicitly put the owner into the owners group for the entity
*/
owned_by_AuthToken_CWUser: number[];
/**
* core relation indicating the types (including specialized types) of an entity
*/
is_instance_of_AuthToken_CWEType: number[];
/**
* core relation indicating the original creator of an entity
*/
created_by_AuthToken_CWUser: number[];
enabled: boolean;
token: string;
id: string;
/**
* creation time of an entity
*/
creation_date: string;
/**
* core relation indicating the type of an entity
*/
is_AuthToken_CWEType: number[];
token_for_user_AuthToken_CWUser: number[];
/**
* latest modification time of an entity
*/
modification_date: string;
identity_AuthToken_AuthToken: number[];
}
export interface AuthorshipActivity extends Activity {
eid: number;
identity_AuthorshipActivity_AuthorshipActivity: number[];
actor_AuthorshipActivity_Person: number[];
actor_AuthorshipActivity_Naturalist: number[];
uri: string;
date: string;
source_AuthorshipActivity_Source: number[];
location_AuthorshipActivity_Location: number[];
created_AuthorshipActivity_Taxon: number[];
based_on_AuthorshipActivity_Specimen: number[];
/**
* internal entity uri
*/
cwuri: string;
cw_source_AuthorshipActivity_CWSource: number[];
/**
* core relation indicating owners of an entity. This relation implicitly put the owner into the owners group for the entity
*/
owned_by_AuthorshipActivity_CWUser: number[];
/**
* core relation indicating the types (including specialized types) of an entity
*/
is_instance_of_AuthorshipActivity_CWEType: number[];
/**
* core relation indicating the original creator of an entity
*/
created_by_AuthorshipActivity_CWUser: number[];
/**
* creation time of an entity
*/
creation_date: string;
/**
* core relation indicating the type of an entity
*/
is_AuthorshipActivity_CWEType: number[];
/**
* latest modification time of an entity
*/
modification_date: string;
identity_AuthorshipActivity_AuthorshipActivity: number[];
}
/**
* abstract base class for transitions
*/
export interface BaseTransition {
eid: number;
identity_BaseTransition_BaseTransition: number[];
/**
* internal entity uri
*/
cwuri: string;
name: string;
type: string;
description: string;
description_format: string;
/**
* link a transition to one or more workflow
*/
transition_of_BaseTransition_Workflow: number[];
require_group_BaseTransition_CWGroup: number[];
cw_source_BaseTransition_CWSource: number[];
condition_BaseTransition_RQLExpression: number[];
/**
* core relation indicating owners of an entity. This relation implicitly put the owner into the owners group for the entity
*/
owned_by_BaseTransition_CWUser: number[];
/**
* core relation indicating the types (including specialized types) of an entity
*/
is_instance_of_BaseTransition_CWEType: number[];
/**
* core relation indicating the original creator of an entity
*/
created_by_BaseTransition_CWUser: number[];
/**
* creation time of an entity
*/
creation_date: string;
/**
* core relation indicating the type of an entity
*/
is_BaseTransition_CWEType: number[];
/**
* latest modification time of an entity
*/
modification_date: string;
identity_BaseTransition_BaseTransition: number[];
by_transition_TrInfo_BaseTransition: number[];